Description
Hi,
We have moved from Log4j1.x to Log4j2.17.1 to fix the Log4j vulnerability and it is a Java application. This is an EJB project and I have placed the xml under src directory. This project is an EAR application. Everything works fine but in one application we have below issue. The requirement is Logs after reaching max size 15 mb should roll over and create new log file and 30 such Log files should be generated before it archives the logs to a folder. But after moving to Log4j 2.17.1 this is not happening. After reaching the max size this log file is getting overridden and data is lost. Also it is writing to the folder immediately without creating the 30 max files.
Below is my Log4j2.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO" name="Test" >
<Properties>
<Property name="filename">${sys:LOGGING_DIR}/TestLog.log</Property>
<property name="name">Test</property>
<property name="pattern">%d [%p] - %c{1} (%M:%L) - %m%n</property>
</Properties>
<Appenders>
<RollingFile name="RollingFile" fileName="${filename}"
filePattern="${sys:LOGGING_DIR}/$${date:yyyy-MM}/${name}%d{yyyy-MM-dd}%i.log.gz">
<PatternLayout>
<pattern>${pattern}</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy /><!-- Rotated everyday -->
<SizeBasedTriggeringPolicy size="15 MB" /> <!-- Or every 100 MB -->
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="RollingFile" />
</Root>
</Loggers>
</Configuration>
I tried all the options shown below to use SizeBased, TimeBased and DefaultRolloverStrategy but still the file gets overridden
<Policies>
<SizeBasedTriggeringPolicy size="10 KB" />
TimeBasedTriggeringPolicy interval="1" />
</Policies>
<DefaultRolloverStrategy max="30"/>
In the attachment provided after reaching 10Kb it is writing a file catcher-2022-04-29-1.log. But again when it reaches 10Kb the logs in this file are getting overridden without creating a new file.
Please let me know what is the issue with my xml file and how to fix this to always create a new file after reaching max size of 15 MB and to create 30 such files before archiving it to a folder.
Please let me know if you need any more details
Thanks
Venu