title: How to initialize log4net before the log file is created?
body: <p>I would like to set the full path and the file name for the log file (I use log4net) and I would like to use the c:\ProgramData\Logs folder. I get the path of the ProgramData folder using the environment variable #PROGRAMDATA#.</p>
  
  <p>I would like to set the path for the log file in the next way: I use a property in the App.config, and I set the value for this property in the class where I do the loggings.</p>
  
  <p>My App.config file:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;configuration&gt;
  ...
      &lt;log4net&gt;
          &lt;appender name="Console" type="log4net.Appender.ConsoleAppender"&gt;
              &lt;layout type="log4net.Layout.PatternLayout"&gt;
                  &lt;!-- Pattern to output the caller's file name and line number --&gt;
                  &lt;conversionPattern value="%5level [%thread] (%file:%line) - %message%newline" /&gt;
              &lt;/layout&gt;
          &lt;/appender&gt;
          &lt;appender name="AppRollingFile" type="log4net.Appender.RollingFileAppender"&gt;
            &lt;file type="log4net.Util.PatternString" value="%property{ProgramDataPath}\Logs\Application.log" /&gt;
            &lt;lockingModel type="log4net.Appender.FileAppender+MinimalLock" /&gt;
              &lt;appendToFile value="true" /&gt;
              &lt;maximumFileSize value="1000KB" /&gt;
              &lt;maxSizeRollBackups value="5" /&gt;
  
              &lt;layout type="log4net.Layout.PatternLayout"&gt;
                  &lt;conversionPattern value="[%-5level][%d{yy-MM-dd HH:mm:ss,fff}] %m%n" /&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="AppRollingFile" /&gt;
          &lt;/root&gt;
      &lt;/log4net&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>And the code where I set the property:</p>
  
  <pre><code>static void Main(string[] args)
  {
      log4net.GlobalContext.Properties["ProgramDataPath"] = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
      log4net.Config.XmlConfigurator.Configure();
  </code></pre>
  
  <p>My problem is that an empty log file is created before the value of the property is set (then the property it is null). The initialization of the log4net it is done before entering in the main function of the class where I set the property, so it will always be created an empty file in the application's folder: bin\Debug(null)\Logs\Application.log. After I set the property, everything works fine, because another Apllication.log file will be created in c:\ProgramData\Logs folder.</p>
  
  <p>My question is that how can I set the value of the property before the empty log file is created/before entering in the main function of the class where I set the property, or what other solution is there?</p>
  
  <p>Using the environment variable in the App.config as it is shown below did not work.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;file type="log4net.Util.PatternString" value="${PROGRAMDATA}\Logs\Application.log"/&gt;
  </code></pre>