0
正如标题中提到,RollingFile附加器有时未能GZ日志文件,有时我得到xxx.txt有时会xxx.gz在存档文件夹中,配置是如下:log4j的2 RollingFile有时未能GZ日志文件
<RollingFile name="dev1Log" fileName="E:/test/logs/dev1Log.txt"
filePattern="E:/test/logs/archived/$${date:yyyy-MM}/dev1Log.txt-%d{yyyy-MM-dd}-%i.txt.gz">
<PatternLayout pattern="%-5p:[%c.class(%c{1}.java:%L)] %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="1 M"/>
</Policies>
<DefaultRolloverStrategy max="100"/>
</RollingFile>
错误日志如下:
2017-09-09 16:26:57,582 ContainerBackgroundProcessor[StandardEngine[Catalina]] T
RACE DefaultRolloverStrategy.purge() took 182.0 milliseconds
2017-09-09 16:26:57,582 ContainerBackgroundProcessor[StandardEngine[Catalina]] D
EBUG RollingFileManager executing synchronous FileRenameAction[E:\andro_web\log4
j\mlWebLogs\xxxdev1Log.txt to E:\andro_web\log4j\mlWebLogs\archived\2017-09\xxxd
ev1Log.txt-2017-09-09-100.txt, renameEmptyFiles=false]
2017-09-09 16:26:57,582 ContainerBackgroundProcessor[StandardEngine[Catalina]] E
RROR Unable to move file E:\andro_web\log4j\mlWebLogs\xxxdev1Log.txt to E:\andro
_web\log4j\mlWebLogs\archived\2017-09\xxxdev1Log.txt-2017-09-09-100.txt: java.ni
o.file.FileSystemException E:\andro_web\log4j\mlWebLogs\xxxdev1Log.txt -> E:\and
ro_web\log4j\mlWebLogs\archived\2017-09\xxxdev1Log.txt-2017-09-09-100.txt: 程序
無法存取檔案,因為檔案正由另一個程序使用。(Chinese means: The program can not access the file because the file is being used by another program.)