title: Trouble logging data from multiple instances to separate log files
body: <p>In my usual logging experiences, I merely create an <code>ILog</code> instance in each class by using something like <code>mylog = LogManager.GetLogger( name)</code>, which gives me a unique Logger per instance.  Everything logs to the same file and works great.</p>
  
  <p>However, now I've got a situation where I want to log to two separate files.  I accomplish this with the following logging.xml:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;log4net&gt;
    &lt;appender name="Console" type="log4net.Appender.ConsoleAppender"&gt;
      &lt;filter type="log4net.Filter.LevelRangeFilter"&gt;
        &lt;param name="LevelMin" value="INFO"/&gt;
        &lt;param name="LevelMax" value="FATAL"/&gt;
      &lt;/filter&gt;
      &lt;layout type="log4net.Layout.PatternLayout"&gt;
        &lt;!-- Pattern to output the caller's file name and line number --&gt;
        &lt;conversionPattern value="%date{yyyy-MM-dd-HH_mm_ss.fff} [%thread] %-5level %logger - %message%newline" /&gt;
      &lt;/layout&gt;
    &lt;/appender&gt;
  
    &lt;appender name="File" type="log4net.Appender.FileAppender"&gt;
      &lt;file type="log4net.Util.PatternString" value="%property{LogName}" /&gt;
      &lt;appendToFile value="true" /&gt;
      &lt;layout type="log4net.Layout.PatternLayout"&gt;
        &lt;conversionPattern value="%date{yyyy-MM-dd-HH_mm_ss.fff} [%thread] %-5level %logger - %message%newline" /&gt;
      &lt;/layout&gt;
    &lt;/appender&gt;
  
    &lt;root&gt;
      &lt;level value="DEBUG" /&gt;
      &lt;appender-ref ref="Console" /&gt;
      &lt;appender-ref ref="File" /&gt;
    &lt;/root&gt;
  &lt;/log4net&gt;
  </code></pre>
  
  <p>and in code behind, I set the name of the <code>FileAppender</code> on a per-instance basis by giving it a unique name:</p>
  
  <p><code>log4net.GlobalContext.Properties["LogName"] = unique_path_here;</code></p>
  
  <p>If I instantiate one object called "test1", the "test1.log" file is created.  When I instantiate another object called "test2", the "test2.log" file is created.  Everything seems like it's working great, until I start to call methods in each object.  When I alternate calls, data for one object gets written to the other object's file at first, but then data gets logged to the correct file.  For example, here's a simplified example of what happens:</p>
  
  <ol>
  <li>test1.log() -> writes to test1.log</li>
  <li>test2.log() -> writes to test2.log</li>
  <li>test1.log() -> writes a line to test2.log, then the rest is written to test1.log</li>
  <li>test2.log() -> writes a lint to test1.log, then the rest is written to test2.log</li>
  </ol>
  
  <p>If I run the two methods in parallel, all lines get written to one file or the other.  Then what's really weird is that the other, mostly-used file is <em>never</em> written to again!</p>
  
  <p>I'm not sure where to look next.  If I've created a Logger instance via GetLogger and passed it a unique name, and this a private member variable, how is it possible that it starts to write to the wrong file?</p>