private static readonly ILog alog = LogManager.GetLogger("AlgoLogger");
public void SwitchToNewUniqueAlgoLogFile(long scheduleID)
{
ILoggerRepository logRepos = LogManager.GetRepository();
IAppender[] logAppenders = logRepos.GetAppenders();
string targetAppenderName = "myAppender"
// first find the logger we are actually looking for
for (int i = 0; i < logAppenders.Length; i++)
{
IAppender appender = logAppenders[i];
if (appender.Name == targetAppenderName )
{
// cast generic appender to our type
RollingFileAppender rfa = appender as RollingFileAppender;
// get full name of current log file
string oldFName = rfa.File;
// extract path
int indexOfLastSlash = oldFName.LastIndexOf(@"\");
string path = oldFName.Substring(0, indexOfLastSlash + 1);
// generate new log file name
string newLogFileName = "newLog.txt"
string newFullFileName = path + newLogFileName;
// set new file name
rfa.File = newFullFileName;
// indicate to change
rfa.ActivateOptions();
break;
}
}
}
Wednesday, October 21, 2009
log4net - Force New (Specified) Log File
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
comment: