问题描述
我将 Microsoft Application Insights
用于我的 Web 应用程序.我使用 Application Insights TraceListener NuGet 包进行日志记录.效果很好.
I am using Microsoft Application Insights
for my Web Application. I used the Application Insights TraceListener NuGet package for logging. That worked perfectly.
现在我想切换到 NLog.我添加了 Microsoft.ApplicationInsights.NLogTarget
NuGet 包并在我的 NLog 配置文件中添加了一个新的 NLog 目标:
Now I would like to switch to NLog. I added the Microsoft.ApplicationInsights.NLogTarget
NuGet package and added a new NLog target in my NLog configuration file:
<target name='ai' xsi:type='ApplicationInsights' />
NLog 抛出异常:
Target cannot be found: 'ApplicationInsights'
我也尝试通过像这样的扩展添加程序集:
I also tried adding the assembly via extensions like so:
<extensions>
<add assembly="Microsoft.ApplicationInsights.NLogTarget" />
</extensions>
但也没有用.
有什么建议吗?
推荐答案
解决方案:(感谢@nemesv 的提示)
Solution: (thanks to @nemesv for the tip)
以编程方式添加目标
ConfigurationItemFactory.Default.Targets.RegisterDefinition(
"ApplicationInsightsTarget",
typeof(Microsoft.ApplicationInsights.NLogTarget.ApplicationInsightsTarget)
);
并与
<target name='ai' xsi:type='ApplicationInsightsTarget' />
这篇关于如何将 Microsoft Application Insights 与 NLog 结合使用(找不到目标:“ApplicationInsights")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!