Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell NLog to log exceptions?

Tags:

nlog

Target:

<targets>
    <target name="file" xsi:type="File" layout="${longdate} ${level} ${message} ${exception}" fileName="${basedir}/log.txt" archiveAboveSize="10485760" />
</targets>

When I call Logger.Error("some message", e), where e is some exception object, it only logs the message, not the exception information. I need it to output exception message and stack trace. Any ideas what I am doing wrong?

like image 376
Andrey Avatar asked Feb 08 '12 18:02

Andrey


People also ask

How do you log exceptions?

To log a handled exceptionCreate the method that will generate the exception information. Use a Try...Catch block to catch the exception. Put the code that could generate an exception in the Try block. Uncomment the Dim and MsgBox lines to cause a NullReferenceException exception.

What are the NLog levels?

Writing Log Messages With NLog The available methods for logging are (in ascending order): Trace, Debug, Info, Warn, Error, and Fatal. Each of these methods creates a log message with a corresponding log level—an indicator of the message's importance.

What is the use of NLog?

NLog is “a free logging platform for . NET, Silverlight and Windows Phone with rich log routing and management capabilities. It makes it easy to produce and manage high-quality logs for your application regardless of its size or complexity.”


1 Answers

Try to use ${exception:innerFormat=Message,StackTrace}. Here is the documentation.

like image 111
kolbasov Avatar answered Sep 22 '22 12:09

kolbasov