Note that there are some explanatory texts on larger screens.

plurals
  1. POnLog conditional layouts
    primarykey
    data
    text
    <p>I'm using nLog 2.0 and after <a href="http://nlog-project.org/2011/04/20/exception-logging-enhancements.html" rel="nofollow">this interesting read</a> I tried to apply conditions to a simple layout as such:</p> <pre><code>layout="${message:when=logger==A}" layout="${message:when=logger=='A'}" layout="${message:when='logger==A'}" </code></pre> <p>Not only do none of these have any effect, they also do not throw an error so it seems the condition is silently swallowed somewhere (<code>throwExceptions</code> is set to true)</p> <ol> <li>How to conditional layouts to work? Do they even work</li> <li>Can nLog throw exceptions if something is wrong/unrecognized?</li> </ol> <p>Here is the full code, this is a basic console application.</p> <p>main.cs:</p> <pre><code>class Program { static void Main( string[] args ) { NLog.LogManager.GetLogger( "A" ).Info( "from A" ); NLog.LogManager.GetLogger( "B" ).Info( "from B" ); } } </code></pre> <p>NLog.config (in executable directory):</p> <pre><code>&lt;?xml version="1.0" ?&gt; &lt;nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true"&gt; &lt;targets&gt; &lt;target name="main" xsi:type="File" fileName="my.log" deleteOldFileOnStartup="true" keepFileOpen="true" layout="${callsite} ${message:when=logger=='A'}"/&gt; &lt;/targets&gt; &lt;rules&gt; &lt;logger name="*" minlevel="Trace" writeTo="main" /&gt; &lt;/rules&gt; &lt;/nlog&gt; </code></pre> <p>Output:</p> <pre><code>ConsoleApplication1.Program.Main from A -&gt; this should only log ${callsite} ConsoleApplication1.Program.Main from B </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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