使用 NLog 进行 Azure 日志流式处理

Dan*_*Dan 3 logging nlog azure

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

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

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

<?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>
Run Code Online (Sandbox Code Playgroud)

我看不出我所做的任何事情与这里接受的答案不同......

如何集成NLog将日志写入Azure Streaming日志

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

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

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

有任何想法吗?

Dan*_*Dan 5

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