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

标签 azure logging nlog

我正在尝试获取 nlog使用 Azure Web 应用程序日志流。

如果我不使用 nlog,而只使用 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>

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

How to integrate NLog to write log to Azure Streaming log

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

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

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

有什么想法吗?

最佳答案

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

关于使用 NLog 进行 Azure 日志流式处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42439564/

相关文章:

c# - 具有持久身份验证的 Azure 移动服务

Azure VIP 交换 - 幕后到底发生了什么

c - 从 err(3) 函数创建日志文件

java - 如何将 java.util.logging.Logger 覆盖到我的私有(private)记录器?

amazon-web-services - Azure 的本地云堆栈类似于 AWS 的 LocalStack?

azure - 如何在 Azure Blob 存储上下载名称带有空格的文件?

java - 记录器是否应该是私有(private)静态的

android - Xamarin 上的 NLog 日志文件 - Android 问题

c# - 未创建 Nlog 日志文件

c# - 当调用 Flush() 时,NLog 是否应该刷新 AsyncTargetWrapper 中所有排队的消息?