exception logging

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

exception logging

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

try {
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:

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

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

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

Re: exception logging

Jason LaFlair
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:


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