Hi I am now using log4net for some time. This is my Logger:
public static class LoggerSetup
{
private static RollingFileAppender _roller;
private static PatternLayout _patternLayout;
static LoggerSetup()
{
// root config
Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
hierarchy.Root.Level = Level.Debug;
hierarchy.Configured = true;
// prepare appender
_roller = new RollingFileAppender();
_patternLayout = new PatternLayout();
_roller.Layout = _patternLayout;
hierarchy.Root.AddAppender(_roller);
_fileDirectory = "Log";
Setup();
}
/// <summary>
/// Location to save logfile
/// </summary>
public static string FileDirectory
{
get
{
return _fileDirectory;
}
set
{
_fileDirectory = value;
Setup();
}
}
private static string _fileDirectory;
public static string DatePattern
{
get { return "_yyyy-MM-dd"; }
}
public static void Setup()
{
_roller.AppendToFile = true;
_roller.File = FileDirectory + @"/" + "Log.log";
_roller.StaticLogFileName = true;
_roller.PreserveLogFileNameExtension = true;
_roller.LockingModel = new FileAppender.MinimalLock();
_roller.MaxSizeRollBackups = -1; //--> Logger doesnt delete files himself
_roller.RollingStyle = RollingFileAppender.RollingMode.Composite;
_roller.MaximumFileSize = "10KB";
_roller.DatePattern = DatePattern;
_patternLayout.ConversionPattern = "%date [%-5level] %message%newline";
_patternLayout.ActivateOptions();
_roller.ActivateOptions();
}
}
As you see, this Appender creates logfiles with maxsize 10K and it will also be rolled daily. This Configruation generates logfilenames as follows:
Log.log_2015-03-04,
Log.1.log_2015-03-04,
- Log.2.log_2015-03-04,
- Log.log_2015-03-03,
- Log.1.log_2015-03-03,
- Log.2.log_2015-03-03
BUT The today created logs look like this
- Log.log,
- Log.1.log,
- Log.2.log
What I want is that filenames look like this : Log_yyyy-mm-dd_nr.log
So how do I change that?