title: Log4Net performance
body: <p>I have written a C# app that runs constantly in a loop and several threads write to a log4net file. </p>
  
  <p>The issue is that the longer the app is running, the more time it takes to complete a loop. I have run a ANTS Performance profiler, and noticed that most of this CPU time is spent logging with log4.net.</p>
  
  <p>The more verbose the logs the more CPU it uses and after 30 minutes it's using 100% of the CPU. If I disable logging the time taken for a loop remains constant over time. I had a look at Windows Performance Monitor and the Physical Disk is most of the time IDLE. </p>
  
  <p>I have tried to keep my logging to a minimum, but even with relatively low amounts of logging im still experiencing the issue.</p>
  
  <p>Here is a sample of my Log4net.xml configuration file:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;log4net&gt;
    &lt;root&gt;
      &lt;!-- Levels: OFF, DEBUG, INFO, WARN, ERROR, FATAL--&gt;
      &lt;level value="INFO" /&gt;
      &lt;appender-ref ref="RollingLogFileAppender" /&gt;
    &lt;/root&gt;
  
    &lt;!--Logs to a file--&gt;
    &lt;appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"&gt;
      &lt;file value="c:\\logs\\log-file.txt" /&gt;
      &lt;appendToFile value="true" /&gt;
      &lt;lockingModel type="log4net.Appender.FileAppender+ExclusiveLock" /&gt;
      &lt;rollingStyle value="Composite" /&gt;
      &lt;datePattern value="yyyyMMdd" /&gt;
      &lt;maxSizeRollBackups value="20" /&gt;
      &lt;maximumFileSize value="1MB" /&gt;
      &lt;layout type="log4net.Layout.PatternLayout"&gt;
        &lt;conversionPattern value="%date [%thread] %-5level %logger %L %M Schdl:[%property{scheduleContext}] Job:[%property{jobContext}] - %message%newline" /&gt;
      &lt;/layout&gt;
    &lt;/appender&gt;
  &lt;/log4net&gt;
  </code></pre>
  
  <p>I am using the same logger from every object that logs.</p>
  
  <pre><code>  log4net.ILog logger;
    log4net.Config.BasicConfigurator.Configure();
    logger = log4net.LogManager.GetLogger(typeof(myProject));
  </code></pre>
  
  <p>Why would it use more and more CPU the longer it runs?</p>
  
  <p>Any advise on how to improve this would be appreciated.</p>