Hi there,
I have my log4net configuration in app.config, and I'm trying to change the file key value. I'm trying to use this method:
static bool ChangeLogFileName(string AppenderName, string NewFilename)
{
log4net.Repository.ILoggerRepository RootRep;
RootRep = log4net.LogManager.GetRepository();
foreach (log4net.Appender.IAppender iApp in RootRep.GetAppenders())
{
if (iApp.Name.CompareTo(AppenderName) == 0
&& iApp is log4net.Appender.FileAppender)
{
log4net.Appender.FileAppender fApp = (log4net.Appender.FileAppender)iApp;
fApp.File = NewFilename;
fApp.ActivateOptions();
return true; // Appender found and name changed to NewFilename
}
}
return false; // appender not found
}
But when I try to call this method ( ChangeLogFileName("RollingFileAppender", "C:\Testv2\abc.log") ) there's no Appenders in RootRep, so this returns false.
I have this in the web.config:
<log4net>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="C:\Test\file.log"/>
<appendToFile value="true"/>
<datePattern value="yyyyMMdd"/>
<rollingStyle value="Date"/>
<staticLogFileName value="true"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"/>
</layout>
</appender>
<root>
<level value="DEBUG"/>
<appender-ref ref="RollingFileAppender"/>
</root>
<logger name="NHibernate">
<level value="ERROR"/>
</logger>
</log4net>