目前我正在使用 NLog 将我的应用程序错误写入文本文件。 除了写入 Azure Blob 存储之外,如何配置 NLog 将错误消息写入 Azure 流日志?
最佳答案
Azure 流日志捕获发送到 Trace 接口(interface)的内容。如果您将 NLog 配置为发送到该目标,则您可以通过 Visual Studio 中的输出窗口轻松访问它。
以下是我如何配置 NLog.config 以获得此结果:
<targets>
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log" layout="${longdate} ${uppercase:${level}} ${message} ${exception:format=tostring}" />
<target xsi:type="Trace" name="trace" layout="${logger} ${message} ${exception:format=tostring}" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="f" />
<logger name="*" minlevel="Trace" writeTo="trace" />
</rules>
第一个目标应该类似于您已经拥有的用于记录到文件的目标,第二个目标只是将数据发送到跟踪 channel 。
希望这对您有所帮助!
关于c# - 如何集成 NLog 将日志写入 Azure Streaming 日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35058029/