【发布时间】:2021-01-01 18:27:14
【问题描述】:
我的基于 .NET 的控制台应用程序有以下 NLog.config。
<targets>
<target xsi:type="File" name="file" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
<target xsi:type="Console" name="console"
layout="${longdate}|${uppercase:${level}}|${message}" />
</targets>
<rules>
<!-- add your logging rules here -->
<logger name="*" minlevel="Debug" writeTo="file" />
<logger name="*" minlevel="Debug" writeTo="console" />
</rules>
我已按照其他地方的说明安装了 Microsoft.ApplicationInsights.Web,一切都按预期运行,例如
var client = new TelemetryClient();
// logging a custom event using the AI API
client.TrackEvent("AppInsights is now ready for logging");
client.Flush();
这与 NLog 输出到文件和控制台一起工作。但是,只要我添加 Microsoft.ApplicationInsights.NLogTarget,所有 NLog 控制台输出和文件输出都会消失,并且也不会出现在 Application Insights 中。
有什么想法吗?我在我的 NLog.config 中尝试了不同的设置,为 Application Insights 设置目标,我所做的没有任何区别。
【问题讨论】:
-
听起来像添加 ApplicationInsights.NLogTarget 会使您的 NLog 配置无效,因此所有日志记录都会停止。记得加
Microsoft.ApplicationInsights.NLogTarget到<extensions>:cmatskas.com/…怎么加 -
如果这不起作用,请激活 NLog 内部记录器并检查线索:github.com/NLog/NLog/wiki/Internal-Logging
-
请参考下面的答案,它现在运行良好。数据可以显示在控制台/文件/应用程序洞察中。非常感谢@RolfKristensen 的帮助。
标签: azure azure-application-insights nlog