Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h2>Treating exceptions differently</h2> <p>We often want to get more information when there is an exception. The following configuration has two targets, a file and the console, which filter on whether or not there is any exception info. (EDIT: Jarek has posted about a <a href="http://nlog-project.org/2011/04/20/exception-logging-enhancements.html" rel="noreferrer">new method of doing this in vNext</a>.)</p> <p>The key is to have a wrapper target with <code>xsi:type="FilteringWrapper" condition="length('${exception}')&gt;0"</code></p> <pre><code>&lt;nlog xmlns="http://www.nlog-project.org/schemas/NLog.mono2.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true" internalLogLevel="Warn" internalLogFile="nlog log.log" &gt; &lt;variable name="VerboseLayout" value="${longdate} ${level:upperCase=true} ${message} (${callsite:includSourcePath=true})" /&gt; &lt;variable name="ExceptionVerboseLayout" value="${VerboseLayout} (${stacktrace:topFrames=10}) ${exception:format=ToString}" /&gt; &lt;targets async="true"&gt; &lt;target name="file" xsi:type="File" fileName="log.log" layout="${VerboseLayout}"&gt; &lt;/target&gt; &lt;target name="fileAsException" xsi:type="FilteringWrapper" condition="length('${exception}')&gt;0"&gt; &lt;target xsi:type="File" fileName="log.log" layout="${ExceptionVerboseLayout}" /&gt; &lt;/target&gt; &lt;target xsi:type="ColoredConsole" name="console" layout="${NormalLayout}"/&gt; &lt;target xsi:type="FilteringWrapper" condition="length('${exception}')&gt;0" name="consoleException"&gt; &lt;target xsi:type="ColoredConsole" layout="${ExceptionVerboseLayout}" /&gt; &lt;/target&gt; &lt;/targets&gt; &lt;rules&gt; &lt;logger name="*" minlevel="Trace" writeTo="console,consoleException" /&gt; &lt;logger name="*" minlevel="Warn" writeTo="file,fileAsException" /&gt; &lt;/rules&gt; &lt;/nlog&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload