简体   繁体   中英

Log4j2 rc 1 DefaultRolloverStrategy overwrites after 7 files

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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM