Note that there are some explanatory texts on larger screens.

plurals
  1. POEliminate duplicate logging in log4net
    primarykey
    data
    text
    <p>I have a program that makes many log4net calls to the "myprogram" loggers. It also calls other code that makes log4net calls to other loggers. I want to capture all logs higher than INFO for "myprogram" and all logs higher than WARN for everything else. This way, I get the work-in-progress messages specific to the task I'm working on, but am still notified of potentially bad things happening in the supporting code. I want this sent to both Console and a log file.</p> <p>I have the following log4net config:</p> <pre class="lang-xml prettyprint-override"><code>&lt;log4net&gt; &lt;root&gt; &lt;level value="WARN" /&gt; &lt;appender-ref ref="Console" /&gt; &lt;appender-ref ref="LogFile" /&gt; &lt;/root&gt; &lt;logger name="myprogram"&gt; &lt;level value="INFO" /&gt; &lt;appender-ref ref="Console" /&gt; &lt;appender-ref ref="LogFile" /&gt; &lt;/logger&gt; &lt;appender name="Console" type="log4net.Appender.ConsoleAppender"&gt; &lt;layout type="log4net.Layout.PatternLayout"&gt; &lt;conversionPattern value="%message%newline" /&gt; &lt;/layout&gt; &lt;threshold value="INFO" /&gt; &lt;/appender&gt; &lt;appender name="LogFile" type="log4net.Appender.RollingFileAppender"&gt; &lt;layout type="log4net.Layout.PatternLayout"&gt; &lt;conversionPattern value="- %utcdate %level %logger %ndc %thread %message%newline" /&gt; &lt;/layout&gt; &lt;appendToFile value="false" /&gt; &lt;staticLogFileName value="true" /&gt; &lt;rollingStyle value="Once" /&gt; &lt;file value="mylogfile" /&gt; &lt;immediateFlush value="true" /&gt; &lt;threshold value="INFO" /&gt; &lt;lockingModel type="log4net.Appender.FileAppender+MinimalLock" /&gt; &lt;/appender&gt; &lt;/log4net&gt; </code></pre> <p>This makes perfect sense to me: log >WARN for everything and >INFO for the specific "myprogram" logger.</p> <p>The problem is that I'm getting INFO messages logged <strong>twice</strong> on both Console and LogFile. This only happens if I have both the <code>&lt;root&gt;</code> and <code>&lt;logger&gt;</code> elements filled though; if I remove either one, then the remaining one works as I expect. </p> <p>I could understand if I was getting double-logging of WARN entries (since myprogram matches both "root" and "myprogram"), but it's happening at INFO even though ROOT is (presumably) set to WARN. </p> <p>Am I doing something wrong here, or is this a log4net bug/ambiguity?</p>
    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.
 

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