使用NLog的Azure日志流 [英] Azure Log Streaming with NLog

查看:74
本文介绍了使用NLog的Azure日志流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让nlog与Azure webapp日志流一起使用.

I'm trying to get nlog working with the Azure webapp Log Stream.

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

The logs do appear if I don't use nlog, and just use System.Diagnostics.Trace.WriteLine.

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

However, if I use the Trace type in my nlog.config, it doesn't show the trace logs ...

<?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>

我在这里看不到与正在接受的答案有所不同的任何事情...

I can't see anything that I'm doing differently from the accepted answer here ...

如何集成NLog写入日志到Azure流日志

请注意,我剪切了nlog.config文件以仅显示跟踪-但我通常也有File目标类型-我尝试过使用此方法,也可以不使用此方法.

Note that I cut down that nlog.config file to just show the trace - but I do normally also have a File target type - I've tried with and without this.

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

I've logged onto the deployed Azure website, and the nlog config file had been uploaded successfully. I'm deploying using the Github deployment.

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

I have the logging set in Azure to just use the file system logging, and I have that set to verbose.

有什么想法吗?

推荐答案

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

It turns out that when Visual Studio enabled Application Insights (a recent thing I added to the project), it had inserted an nlog config section into my web.config. This had then meant that my nlog.config file wasn't being used at all. I've fixed it by removing that nlog config section from my web.config, and copying the Application Insights target into my nlog.config file instead. The 'Trace' target type now works as expected and is appearing in the Azure Streaming Logs.

这篇关于使用NLog的Azure日志流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆