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?
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.
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.
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.”
Try to use ${exception:innerFormat=Message,StackTrace}
. Here is the documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With