title: How to change log file names in Log4net at run time using C#
body: <p>I am writing logs in log file using Log4Net and stored it in local temp folder location (C:\temp..). Now I want to change the text (log) file name at Run time so I have done some code changes on my config file as well as in my application also. But The file name could not be changed on the local temp folder and the log also didn't get written on the text file. </p>
  
  <p>Can you please anyone tell me the solution of this problem or tell me some other examples to work out this problem?</p>
  
  <p>Here My code is:</p>
  
  <p><strong>My Config File(Web.Config) settings :</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;appender name="RollingPatternFileAppender"  type="log4net.Appender.RollingFileAppender"&gt;
      &lt;file type="log4net.Util.PatternString" value="%property{LogFileName}.log" /&gt;
      &lt;appendToFile value="true" /&gt;
      &lt;rollingStyle value="Size" /&gt;
      &lt;maxSizeRollBackups value="10" /&gt;
      &lt;maximumFileSize value="100MB" /&gt;
      &lt;staticLogFileName value="false" /&gt;
      &lt;layout type="log4net.Layout.PatternLayout"&gt;
          &lt;conversionPattern value="%date{yyyy-MM-dd HH:mm:ss} %-5level : [%logger] - %message %newline" /&gt;
      &lt;/layout&gt;
  &lt;/appender&gt;
  &lt;logger name="SPM.SERVER"&gt;
      &lt;level value="DEBUG" /&gt;
      &lt;appender-ref ref="RollingPatternFileAppender" /&gt;
  &lt;/logger&gt;
  </code></pre>
  
  <p><strong>My Application Code is:</strong></p>
  
  <pre><code>ILog logger = LogManager.GetLogger("SPM.SERVER");
  log4net.ThreadContext.Properties["LogFileName"] = "MyLog";
  logger.Debug("Load Data",ex);
  XmlConfigurator.Configure();
  </code></pre>
  
  <p>This code didn't write the log inside of the file and didn't change the file name as well. Anyone please correct what I did wrong in this code or tell me some other examples to achieve this solution. </p>