【问题标题】:Azure Log Streaming with NLog使用 NLog 进行 Azure 日志流式传输
【发布时间】:2017-02-24 13:14:38
【问题描述】:

我正在尝试让 nlog 使用 Azure webapp 日志流。

如果我不使用 nlog 会出现日志,而只需使用 System.Diagnostics.Trace.WriteLine

但是,如果我在我的 nlog.config 中使用 Trace 类型,它不会显示跟踪日志...

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <targets>
        <target xsi:type="Trace" name="trace" layout="${message}" />
    </targets>

    <rules>
        <logger name="*" minlevel="Trace" writeTo="trace" />
    </rules>
</nlog>

我看不出我所做的与此处接受的答案有什么不同...

How to integrate NLog to write log to Azure Streaming log

请注意,我删除了该 nlog.config 文件以仅显示跟踪 - 但我通常也有一个 File 目标类型 - 我尝试过使用和不使用这个。

我已经登录到部署的Azure网站,nlog配置文件已经上传成功。我正在使用 Github 部署进行部署。

我在 Azure 中将日志记录设置为仅使用文件系统日志记录,并将其设置为 verbose

有什么想法吗?

【问题讨论】:

    标签: azure logging nlog


    【解决方案1】:

    事实证明,当 Visual Studio 启用 Application Insights(我最近添加到项目中的一项功能)时,它在我的 web.config 中插入了一个 nlog 配置部分。这意味着我的 nlog.config 文件根本没有被使用。我已通过从我的 web.config 中删除该 nlog 配置部分并将 Application Insights 目标复制到我的 nlog.config 文件中来修复它。 “跟踪”目标类型现在可以按预期工作,并出现在 Azure 流日志中。

    【讨论】:

      【解决方案2】:

      NLog-Trace-Target 仅对调试级日志事件执行 Trace.WriteLine。

      也许可以试试这里显示的自定义 MyTraceTarget:

      https://github.com/NLog/NLog/issues/1968

      更新 NLog 版本。 4.5 为 NLog Trace-target 添加了新设置rawWrite,因此它始终执行独立于 LogLevel 的 WriteLine。另见https://github.com/NLog/NLog/wiki/Trace-target

      【讨论】:

      • 谢谢。您对自定义目标的建议使我走上了正确的道路,因为自定义目标也不起作用,所以我最终在调试器中查看了 LogManger.Configuration,这向我展示了实际问题。赞成:)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多