Reputation: 3954
I have the following configuration file for Log4j2:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="error" name="D3Hooks" packages="">
<Appenders>
<RollingFile append="true" name="RollingFile" fileName="D:\temp\logs\hooks.log" filePattern="hooks.log.%d{dd-MM-yyyy}.log">
<Policies>
<TimeBasedTriggeringPolicy />
</Policies>
<DefaultRolloverStrategy max="30"/>
<PatternLayout pattern="%d{dd-MM-yyyy HH:mm:ss} %level %c.%m %ex{full} %n"/>
</RollingFile>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="RollingFile"/>
</Root>
</Loggers>
</Configuration>
What I expect from this configuration is that a new log file is created daily and 30 log files are kept. What happens instead is that there is only one log file which is overwritten daily. What am I doing wrong?
Upvotes: 2
Views: 4040
Reputation: 475
<PatternLayout pattern="%d{dd-MM-yyyy HH:mm:ss} %level %c.%m %ex{full} %n"/>
</RollingFile>
The log file will create 1 file per day which the interval setting equal to 1 when the pattern layout with pattern="%d{yyyy-MM-dd}. Because the interval is dependent to the log file name format. If the file name have something like HH:mm:ss
it will create a file per second.
Upvotes: 0
Reputation: 3821
For the TimeBasedTriggeringPolicy you should set interval="1" and modulate="true".
See also Time based triggering policy in log4j2
Upvotes: 1