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

1

8

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

Coral answered 18/8, 2020 at 19:16 Comment(0)
G
10

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.

Gambell answered 18/8, 2020 at 23:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.