gpt4 book ai didi

NLog 在同一个文件中记录错误两次

转载 作者:行者123 更新时间:2023-12-03 15:14:09 32 4
gpt4 key购买 nike

我想弄清楚为什么 NLog 两次记录我的错误。

这是我的配置文件:

<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="debug" xsi:type="File" FileName="DebugTestFile.log" layout="${message} ${exception:format=tostring}" />
</targets>
<rules>
<logger name="*" level="Debug" writeTo="debug" />
</rules>
</nlog>

现在当我打电话时 NLog.Debug(myException);输出是我的异常被打印两次。

如果我打电话 NLog.Debug(myException, "My Test Message String");然后错误与我的测试消息一起打印出来。

我到底做错了什么?根据 https://github.com/NLog/NLog/wiki/How-to-Log-Exceptions我的配置是正确的。

我尝试将布局更改为以下内容: layout="${message}当我跑 NLog.Debug(myException);它只打印了一次错误。

但是现在当我跑 NLog.Debug(myException, "My Test Message String");它只打印了我的消息,而没有来自异常的错误。

这可能是 NLog 的错误吗?

最佳答案

如果您在 AspNetCore 中使用 NLog,则问题可能是通过调用 UseNLog 引起的。连同AddNLogConfigureNLog .

您应该只使用 UseNLog连同NLog.Web.LogBuilder.ConfigureNLog (停止使用 AddNLog ):

https://github.com/NLog/NLog/wiki/Getting-started-with-ASP.NET-Core-2#4-update-programcs

关于NLog 在同一个文件中记录错误两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33613971/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com