我真的想知道为什么log4j2无法在不使用onstartuptriggeringpolicy的情况下删除旧的日志文件。
这一个log4j配置有效:
<RollingFile name="CONFIGLOG" append="true" fileName="../log/config.log"
filePattern="../log/config-%d{yyyy-MM-dd}.log">
<PatternLayout pattern="%d %-5p %c{3} [%t]: %m%n" />
<Policies>
<OnStartupTriggeringPolicy/>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="100 MB" />
</Policies>
<DefaultRolloverStrategy>
<Delete basePath="../log" maxDepth="1">
<IfFileName glob="config-*.log">
<IfLastModified age="30d"/>
</IfFileName>
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
但是,当我尝试没有onstartuptriggeringpolicy,它不起作用。这是一个无效的。
<RollingFile name="CONFIGLOG" append="true" fileName="../log/config.log"
filePattern="../log/config-%d{yyyy-MM-dd}.log">
<PatternLayout pattern="%d %-5p %c{3} [%t]: %m%n" />
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="100 MB" />
</Policies>
<DefaultRolloverStrategy>
<Delete basePath="../log" maxDepth="1">
<IfFileName glob="config-*.log">
<IfLastModified age="30d"/>
</IfFileName>
</Delete>
</DefaultRolloverStrategy>
</RollingFile>