Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stacktrace is not being logged by Nlog

My NLog is configured as follows

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <targets>
      <target name="file" xsi:type="File" fileName="${basedir}/log${shortdate}.txt" archiveAboveSize="500000" archiveEvery="Day" archiveNumbering="Rolling" maxArchiveFiles="10" layout="${date:format=s}|${level}|${callsite}|${identity}|${message}|${exception:format=stacktrace}"/>
      <!--<target name="console" xsi:type="Console" />-->
    </targets>
    <rules>
      <logger name="*" minlevel="Debug" writeTo="file" />
      <!--<logger name="*" minlevel="Debug" writeTo="console" />-->
    </rules>
  </nlog>

But the stacktrace is not being logged when exception occurs. Is there a bug in NLog?

I have created a wrapper around Nlog and I am logging as follows

public void Error(string message, Exception ex)
    {
        logger.Error(message, ex);
    }

I get the message in the log but not the stacktrace.

Thanks in advance

like image 751
TrustyCoder Avatar asked Oct 28 '25 05:10

TrustyCoder


1 Answers

Try this in your layout:

${exception:format=ToString}
like image 99
StriplingWarrior Avatar answered Oct 30 '25 23:10

StriplingWarrior