title: How can I change the file location programmatically?
body: <p>I am totally new to Log4net.  I have managed to get something going by adding a config file and simple logging.  I have hardcoded the value to be <code>"C:\temp\log.txt"</code> but this is not good enough.  </p>
  
  <p>The logs must go to the special folders</p>
  
  <pre><code>path = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
  </code></pre>
  
  <p>and this path changes depending whether you are using Windows Server 2008 or Windows XP or Vista etc...</p>
  
  <p>How can I just change the location of the file in log4net programmatically?</p>
  
  <p>This is what I have done:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;configSections&gt;
  &lt;section name="log4net"
           type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/&gt;
  &lt;/configSections&gt;
  &lt;log4net&gt;         
      &lt;root&gt;
          &lt;level value="DEBUG" /&gt;
          &lt;appender-ref ref="LogFileAppender" /&gt;
      &lt;/root&gt;
      &lt;appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender"&gt;
          &lt;param name="File" value="C:\temp\log.txt" /&gt;
          &lt;param name="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;layout type="log4net.Layout.PatternLayout"&gt;
              &lt;param name="ConversionPattern" value="%-5p%d{yyyy-MM-dd hh:mm:ss} – %m%n" /&gt;
          &lt;/layout&gt;
      &lt;/appender&gt;
  &lt;/log4net&gt;
  </code></pre>
  
  <hr>
  
  <pre><code>class Program
  {
      protected static readonly ILog log = LogManager.GetLogger(typeof(Program));
  
      static void Main(string[] args)
      {
          log4net.Config.XmlConfigurator.Configure();
          log.Warn("Log something");
  
          path = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
  
  
          // How can I change where I log stuff?
      }
  }
  </code></pre>
  
  <p>Just need to figure out how I can change to log stuff to where I want to. </p>
  
  <p>Any suggestions?
  Thanks  a lot</p>