Migration from log4j to log4j2:the equivalent attribute to MaxFileSize and MaxBackupIndex

Viewed 7221

My question is regarding LoggerAppenderRollingFile in log4j. Due to some changes in project I have to upgarde to log4j2, and my question is what are the equivalnet attribute to "MaxFileSize", and "MaxBackupIndex". that part of the log4j.xml looks as follow:

<appender name="profilingAppender" class="org.apache.log4j.RollingFileAppender">
        <param name="file" value="C:\\logs\\test.log"/>
        <param name="MaxFileSize" value="20000KB"/>
        <param name="MaxBackupIndex" value="5"/>
        <param name="encoding" value="UTF-8" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d [%t] %-5p %c - [%X{USER}] - %m%n" />
        </layout>
</appender>

Kind regards

1 Answers

In Log4j 2 those values are associated with the triggering policy or RolloverStrategy. MaxFileSize moves to the size attribute of the SizeBasedTriggeringPolicy and MaxBackupIndex moves to become the max attribute of the DefaultRolloverStrategy. You can find examples in the documentation of the RollingFileAppender.

Related