Log4j2 rc 1 DefaultRolloverStrategy overwrites after 7 files

4.7k views Asked by At

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?

1

There are 1 answers

2
Luke Woodward On BEST ANSWER

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:

ERROR Policies has no parameter that matches element DefaultRolloverStrategy

Move it up a level so that it's a direct child of the <RollingFile> element.