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.
Can you please anyone tell me the solution of this problem or tell me some other examples to work out this problem?
Here My code is:
My Config File(Web.Config) settings :
<appender name="RollingPatternFileAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="%property{LogFileName}.log" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="100MB" />
<staticLogFileName value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date{yyyy-MM-dd HH:mm:ss} %-5level : [%logger] - %message %newline" />
</layout>
</appender>
<logger name="SPM.SERVER">
<level value="DEBUG" />
<appender-ref ref="RollingPatternFileAppender" />
</logger>
My Application Code is:
ILog logger = LogManager.GetLogger("SPM.SERVER");
log4net.ThreadContext.Properties["LogFileName"] = "MyLog";
logger.Debug("Load Data",ex);
XmlConfigurator.Configure();
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.