如何集成 NLog 将日志写入 Azure Streaming 日志
How to integrate NLog to write log to Azure Streaming log
目前我正在使用 NLog 将我的应用程序错误写入文本文件。
除了写入 Azure Blob 存储之外,如何配置 NLog 将错误消息写入 Azure 流日志?
Azure 流日志捕获发送到 Trace 接口的内容。如果您将 NLog 配置为发送到该目标,则您可以通过 Visual Studio 中的输出 window 轻松访问该目标。例如。
以下是我如何配置 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>
第一个目标应该类似于您已有的用于记录到文件的目标,第二个目标只是将数据发送到跟踪通道。
希望对您有所帮助!
目前我正在使用 NLog 将我的应用程序错误写入文本文件。 除了写入 Azure Blob 存储之外,如何配置 NLog 将错误消息写入 Azure 流日志?
Azure 流日志捕获发送到 Trace 接口的内容。如果您将 NLog 配置为发送到该目标,则您可以通过 Visual Studio 中的输出 window 轻松访问该目标。例如。
以下是我如何配置 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>
第一个目标应该类似于您已有的用于记录到文件的目标,第二个目标只是将数据发送到跟踪通道。
希望对您有所帮助!