I am trying to figure out why NLog logs my error twice.
here is my config file:
<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>
Now when I call NLog.Debug(myException);
the output is my exception gets printed twice.
If I call NLog.Debug(myException, "My Test Message String");
then the error gets printed out once along with my test message.
What exactly am I doing wrong? According to https://github.com/NLog/NLog/wiki/How-to-Log-Exceptions my configuration is correct.
I tried changing my layout to the following: layout="${message}
and when I ran NLog.Debug(myException);
it only printed the error once.
However now when I ran NLog.Debug(myException, "My Test Message String");
it only printed my message without the error that comes from exception.
Could this be a bug with NLog?
If you are using NLog in AspNetCore, then the problem can be caused by calling UseNLog
together with AddNLog
or ConfigureNLog
.
You should only use UseNLog
together with NLog.Web.LogBuilder.ConfigureNLog
(Stop using AddNLog
):
https://github.com/NLog/NLog/wiki/Getting-started-with-ASP.NET-Core-2#4-update-programcs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With