exception logging

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

exception logging

milosko
Hello I started using NLog and I have some excpetions I want to log, code sample is like this:

try {
    blabla;
}
catch (SomeExceptionType ex)
{
    logger.ErrorException("this is some exception", ex);
}

and when exception occurs, all I see in log is text "this is some exception", but I also want to see message of exception, how can this be done? My config file looks like this:

  <targets>
    <target name="logfile" xsi:type="File" fileName="log.txt" />
    <target name="console" xsi:type="Console"/>
  </targets>

  <rules>
    <logger name="*" minlevel="Info" writeTo="logfile" />
    <logger name="*" minlevel="Info" writeTo="console" />
  </rules>

Thanks for help!
Reply | Threaded
Open this post in threaded view
|

Re: exception logging

Jason LaFlair
Administrator
The 'default' layout for a target is usually ${longdate}|${level:uppercase=true}|${logger}|${message}

If you want to add the exception text you can try this:

${longdate}|${level:uppercase=true}|${logger}|${message}|${exception}

or if you don't want the trailing | you when there isn't an exception try:

${longdate}|${level:uppercase=true}|${logger}|${message}|${onexception:inner=|${exception}}