Log4j2 rc 1 DefaultRolloverStrategy overwrites after 7 files

I am using lo4j2 rc1 with RollingFile support TimeBasedTriggeringPolicy, SizeBasedTriggeringPolicy and DefaultRolloverStrategy with max files as 50. But file rollback is 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?

+3


source to share


1 answer


Your item <DefaultRolloverStrategy max="50"/>

is in the wrong place.

It is not a policy, so it does not belong to the item <Policies>

. In fact, you can see the following in your logs:



ERROR Policies has no parameter that matches element DefaultRolloverStrategy

      

Move it to the level so that it is a direct child of the element <RollingFile>

.

+5


source







All Articles