title: log4net not logging in worker threads with MinimalLock model
body: <p>I have a rater "interesting" problem, where log4net doesn't write the log messages if they come from inside a worker thread in ASP.NET MVC. This seems to only be an issue when I've added <code>&lt;lockingModel type="log4net.Appender.FileAppender+MinimalLock" /&gt;</code> to my log4net configuration and when the website is running on my server (IIS 8.0). On my own computer log4net logs the messages just fine - even with the <code>MinimalLock</code> configuration and if I remove this 'MinimalLock' it will log messages in worker threads on the server as well. </p>
  
  <p>Here is an example:</p>
  
  <pre><code>public class MvcApplication : System.Web.HttpApplication
  {
      private static readonly log4net.ILog log = log4net.LogManager.GetLogger(
          System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  
  
      protected void Application_Start()
      {
  
          // This is logged just fine - with or without MinimalLock, 
          // both local and on server
          log.Info("Logging ouside worker!");
  
          // This is only logged without MinimalLock configured 
          // if the site is hosted on my server runnning IIS 8.0.
          var thread = new Thread(() =&gt; log.Info("Logging inside worker!"));
          thread.Start();
      }
  
  }
  </code></pre>
  
  <p>and here is my log4net configuration:</p>
  
  <pre><code>&lt;log4net&gt;
    &lt;root&gt;
      &lt;level value="ALL" /&gt;
      &lt;appender-ref ref="LogFileAppender" /&gt;
    &lt;/root&gt;
    &lt;appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender"&gt;
      &lt;file value="App_Data\log.log" /&gt;
      &lt;appendToFile value="true" /&gt;
      &lt;rollingStyle value="Size" /&gt;
      &lt;maxSizeRollBackups value="10" /&gt;
      &lt;maximumFileSize value="10MB" /&gt;
      &lt;staticLogFileName value="true" /&gt;
      &lt;lockingModel type="log4net.Appender.FileAppender+MinimalLock" /&gt;
      &lt;layout type="log4net.Layout.PatternLayout"&gt;
        &lt;conversionPattern value="%date [%thread] %level %logger - %message%newline" /&gt;
      &lt;/layout&gt;
    &lt;/appender&gt;
  &lt;/log4net&gt;
  </code></pre>
  
  <p>Without the MinimalLock lockingModel configured, I'm unable to read the log file on the server, so removing it isn't really an option. I'm also unable to avoid logging inside of worker threads, as I need to log potential errors inside of the workers spawned by Quartz.net. </p>
  
  <p>I suspect it is an issue of permissions on the server, but I have very limited access to the server, as I'm not the administrator (I basically only have FTP access - they won't even grant me external access to the MSSQL DB). </p>
  
  <p><strong>Here's the question</strong></p>
  
  <p>If my suspicion is correct, what changes should I request from my server administrator in order to fix the problem? Which permissions should be granted to which user, in order for MinimalLock to work properly in my hosted environment? </p>
  
  <p>If it is not an issue with permissions, what could it be instead?</p>
  
  <p>Any help is much appreciated. Thanks in advance.</p>
  
  <p><strong>Update:</strong> </p>
  
  <p>After enabling the debug log for log4net, I found the following errors when I run the example code above (full path omitted):</p>
  
  <pre><code>log4net:ERROR [RollingFileAppender] Unable to acquire lock on file App_Data\log.log. Access to the path 'App_Data\log.log' is denied.
  log4net:ERROR [RollingFileAppender] Unable to acquire lock on file App_Data\log.log. Access to the path 'App_Data\log.log' is denied.
  log4net:ERROR [RollingFileAppender] Unable to acquire lock on file App_Data\log.log. Access to the path 'App_Data\log.log' is denied.
  log4net: ConfigureAndWatchHandler: Changed [web.config]
  log4net: ConfigureAndWatchHandler: Changed [web.config]
  log4net: Hierarchy: Shutdown called on Hierarchy [log4net-default-repository]
  log4net:ERROR [RollingFileAppender] Unable to acquire lock on file App_Data\log.log. Access to the path 'App_Data\log.log' is denied.
  log4net:ERROR [RollingFileAppender] Could not close writer [log4net.Util.CountingQuietTextWriter]
  log4net.Appender.FileAppender+LockingStream+LockStateException: The file is not currently locked
     at log4net.Appender.FileAppender.LockingStream.AssertLocked()
     at log4net.Appender.FileAppender.LockingStream.Flush()
     at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
     at System.IO.StreamWriter.Dispose(Boolean disposing)
     at System.IO.StreamWriter.Close()
     at log4net.Util.QuietTextWriter.Close()
     at log4net.Appender.TextWriterAppender.CloseWriter()
  </code></pre>
  
  <p>These only occur on the server.</p>