I am using lo4j2 rc1 with RollingFile holding TimeBasedTriggeringPolicy, SizeBasedTriggeringPolicy and DefaultRolloverStrategy having Max files as 50. But the rolled back files are overwritten after 7 files. Below is my configuration
<Appenders>
<Routing name="ServerLogs">
<Routes pattern="$${ctx:logRouter}/">
<Route>
<RollingFile name="ServerLogs" immediateFlush="false" append="false"
fileName="${loghome}/${ctx:logRouter}/ServerLogs.log"
filePattern="${loghome}/${ctx:logRouter}/%d{dd-MM-yyyy}-ServerLogs-%i.log.gz">
<PatternLayout>
<Pattern>%d %p %-40C{1.} [%t] %m %ex%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1"
modulate="true" />
<SizeBasedTriggeringPolicy size="4 MB" />
<DefaultRolloverStrategy max="50"/>
</Policies>
</RollingFile>
</Route>
</Routes>
</Routing>
</Appenders>
<Loggers>
<AsyncLogger name="AsyncServerLogs" level="TRACE" includeLocation="false">
<AppenderRef ref="ServerLogs"/>
</AsyncLogger>
<Root level="DEBUG" includeLocation="false">
<AppenderRef ref="ServerLogs" level="TRACE" />
</Root>
</Loggers>
Am i missing any configuration?
Your
<DefaultRolloverStrategy max="50"/>
element is in the wrong place.It's not a policy, so it doesn't belong in the
<Policies>
element. In fact, you may even see the following in your logs:Move it up a level so that it's a direct child of the
<RollingFile>
element.