文件名生成为" Application.log.1"达到maxFileSize

时间:2016-10-05 08:42:10

标签: log4j

下面是Log4J.properties配置(使用jar" log4j-1.2.17.jar")

log4j.logger.devpinoyLogger=DEBUG, dest1
log4j.appender.dest1=org.apache.log4j.RollingFileAppender
log4j.appender.dest1.maxFileSize=1KB
log4j.appender.dest1.maxBackupIndex=3
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout
log4j.appender.dest1.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss} %c%m%n
log4j.appender.dest1.File=log\\Application.log
log4j.appender.dest1.Append=false

但是一旦达到maxFileSize,备份日志文件就会生成为Application.log.1

我希望将文件生成为Application1.log

我使用RollingFileAppender获得了解决方案。

log4j.logger.devpinoyLogger=DEBUG, dest1
log4j.appender.dest1=org.apache.log4j.rolling.RollingFileAppender
log4j.appender.dest1.rollingPolicy=org.apache.log4j.rolling.FixedWindowRollingPolicy
log4j.appender.dest1.triggeringPolicy=org.apache.log4j.rolling.SizeBasedTriggeringPolicy
log4j.appender.dest1.triggeringPolicy.MaxFileSize=100
log4j.appender.dest1.rollingPolicy.FileNamePattern=C:\\TRB Workspace\\TRBAutomationFramework\\log\\Application-%i.log
log4j.appender.dest1.rollingPolicy.ActiveFileName=C:\\TRB Workspace\\TRBAutomationFramework\\log\\Application.log
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout
log4j.appender.dest1.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss} %c %m%n
log4j.appender.dest1.Append=false

还需要" apache-log4j-extras-1.2.17.jar"

1 个答案:

答案 0 :(得分:0)

我没有测试,但正如Koning所解释的那样,您可以尝试将其添加到您的属性中:

log4j.appender.dest1.rollingPolicy=org.apache.log4j.rolling.FixedWindowRollingPolicy
log4j.appender.dest1.triggeringPolicy=org.apache.log4j.rolling.SizeBasedTriggeringPolicy
log4j.appender.dest1.rollingPolicy.FileNamePattern=log\\Application-%i.log
log4j.appender.dest1.rollingPolicy.ActiveFileName=log\\Application.log