Why does errorexception not log the exception info

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

Why does errorexception not log the exception info

NLoggerBen
Hi,

I am using the ErrorException fucntion to log a message and exception details.  However, in my log I only get the message (at the error level) and no exception details.  I was kinda expecting to see at lease Exception.Message.

Anyone know what I am doing wrong?  I have checked the forum and googled to no avail.  Any help would be appreciated.  Is it possible I am not deploying the right assemblies or something?  

Example code is below:

                        catch(Exception ex)
                        {
                                logger.ErrorException("Startup error.",ex);
}

This turns up in log as...

2006-02-07 13:50:13.6783|ERROR|MyErrorClassName|Startup error.

As you can see.  No exception details.

Please help.

Reply | Threaded
Open this post in threaded view
|

Re: Why does errorexception not log the exception info

Jarek Kowalski
Administrator
There's a special ${exception} layout renderer which you can use to get various details about your exception. Search the mailing list for more information.

Jarek
NLog Blog
Reply | Threaded
Open this post in threaded view
|

Re: Why does errorexception not log the exception info

NLoggerBen
Thank you for the tip Jarek.

For anyone reading this, this is what I found.  I needed to add a layout attribute to my nLog target configuration element.  I then added exception into the layout formatting string as below:

<target name="file1" type="File" filename="server.log" layout="${longdate}|${level:uppercase=true}|${logger}|${callsite}|${message}|<b>${exception}" />
                         
For some reason, stacktrace did not work for me.  It said [unknown layout target:stacktrace:].  I can live without that but if anyone knows why let me know.

Reply | Threaded
Open this post in threaded view
|

Re: Why does errorexception not log the exception info

yaplex.com
This should work for you
${exception:format=tostring}