I would like to have files named for example:
dd.mm.yyyy.log
How is this possible with log4net?
I would like to have files named for example:
dd.mm.yyyy.log
How is this possible with log4net?
In your Log4net config file, use the following parameter with the RollingFileAppender:
<param name="DatePattern" value="dd.MM.yyyy'.log'" />
For a RollingLogFileAppender you also need these elements and values:
<rollingStyle value="Date" />
<staticLogFileName value="false" />
The extended configuration section in a previous response with
...
...
<rollingStyle value="Composite" />
...
...
listed works but I did not have to use
<staticLogFileName value="false" />
. I think the RollingAppender must (logically) ignore that setting since by definition the file gets rebuilt each day when the application restarts/reused. Perhaps it does matter for immediate rollover EVERY time the application starts.
I moved configuration to code to enable easy modification from CI using system variable. I used this code for file name and result is 'Log_03-23-2020.log'
log4net.Repository.ILoggerRepository repository = LogManager.GetRepository(Assembly.GetEntryAssembly());
Hierarchy hierarchy = (Hierarchy)repository;
PatternLayout patternLayout = new PatternLayout();
patternLayout.ConversionPattern = "%date %level - %message%newline%exception";
patternLayout.ActivateOptions();
RollingFileAppender roller = new RollingFileAppender();
roller.AppendToFile = true;
roller.File = "Log_";
roller.DatePattern = "MM-dd-yyyy'.log'";
roller.Layout = patternLayout;
roller.MaxFileSize = 1024*1024*10;
roller.MaxSizeRollBackups = 10;
roller.StaticLogFileName = false;
roller.RollingStyle = RollingFileAppender.RollingMode.Composite;
roller.ActivateOptions();
hierarchy.Root.AddAppender(roller);