log4j2翻转策略未按预期工作

时间:2016-05-26 01:31:59

标签: log4j2 weblogic12c

我将Log4j2.xml定义为:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG">
    <Properties>
        <Property name="log-path">E:/MLM/MLMDomain/servers/${sys:weblogic.Name}/logs</Property>
    </Properties>
    <Appenders>
        <RollingFile name="RollingFile" fileName="${log-path}/MLMServices.log" filePattern="${log-path}/MLMServices-%d{yyyy-MM-dd}-%i.log" >
            <PatternLayout>
                <pattern>%d{dd/MMM/yyyy HH:mm:ss.SSS} [%-5level] [%c{1}] %m%n</pattern>
            </PatternLayout>
            <Policies>
                <SizeBasedTriggeringPolicy size="1 MB" />
            </Policies>
            <DefaultRolloverStrategy max="30"/>
        </RollingFile>
    </Appenders>
    <Loggers>
        <Logger name="root" level="debug" additivity="false">
           <appender-ref ref="RollingFile" level="debug"/>
        </Logger>
        <Root level="debug" additivity="false">
            <AppenderRef ref="RollingFile"/>
       </Root>
    </Loggers>
</Configuration>

根据我的理解,当我的日志文件达到1MB时,它应该转到新的日志文件。要翻转的文件数应为30.但是,如果查看下面的日志,则其中有40多个,而所有最新的文件都接近30MB。当前日志文件MLMServices.log包含2016年4月13日至今的条目。实际上,最后几个日志文件MLMServices-2016-05-24-4.log,MLMServices-2016-05-24-3.log等都有2016年4月13日的条目。创建新的日志文件时,它复制前一个条目,然后附加更多条目。因此,每个新的日志文件将逐渐大于前一个。

04/28/2016  04:26 PM         1,050,290 MLMServices-2016-04-28-1.log
04/28/2016  06:02 PM         1,188,994 MLMServices-2016-04-28-2.log
04/29/2016  12:11 PM         1,315,487 MLMServices-2016-04-29-1.log
04/29/2016  12:21 PM         1,364,634 MLMServices-2016-04-29-2.log
04/29/2016  12:30 PM         1,413,781 MLMServices-2016-04-29-3.log
04/29/2016  05:02 PM         1,472,373 MLMServices-2016-04-29-4.log
05/03/2016  04:16 PM         2,521,056 MLMServices-2016-05-03-1.log
05/04/2016  04:35 PM         3,379,593 MLMServices-2016-05-04-1.log
05/05/2016  01:47 PM         3,715,698 MLMServices-2016-05-05-1.log
05/05/2016  02:47 PM         3,858,833 MLMServices-2016-05-05-2.log
05/06/2016  02:13 PM         4,908,446 MLMServices-2016-05-06-1.log
05/06/2016  02:46 PM         4,927,119 MLMServices-2016-05-06-2.log
05/06/2016  03:04 PM         5,068,610 MLMServices-2016-05-06-3.log
05/06/2016  05:07 PM         5,267,743 MLMServices-2016-05-06-4.log
05/10/2016  03:16 PM         8,598,426 MLMServices-2016-05-10-1.log
05/10/2016  03:16 PM        11,280,054 MLMServices-2016-05-10-2.log
05/10/2016  03:16 PM        12,328,667 MLMServices-2016-05-10-3.log
05/10/2016  03:16 PM        13,377,298 MLMServices-2016-05-10-4.log
05/10/2016  03:16 PM        14,425,881 MLMServices-2016-05-10-5.log
05/10/2016  03:16 PM        15,474,464 MLMServices-2016-05-10-6.log
05/10/2016  03:16 PM        16,523,059 MLMServices-2016-05-10-7.log
05/10/2016  03:16 PM        17,571,640 MLMServices-2016-05-10-8.log
05/10/2016  03:53 PM        18,620,566 MLMServices-2016-05-10-9.log
05/11/2016  02:37 PM        19,002,926 MLMServices-2016-05-11-1.log
05/11/2016  02:44 PM        19,088,104 MLMServices-2016-05-11-2.log
05/11/2016  03:50 PM        19,375,771 MLMServices-2016-05-11-3.log
05/14/2016  01:51 PM        20,424,415 MLMServices-2016-05-14-1.log
05/16/2016  12:52 PM        21,473,018 MLMServices-2016-05-16-1.log
05/17/2016  07:01 PM        22,521,671 MLMServices-2016-05-17-1.log
05/18/2016  09:57 AM        23,570,365 MLMServices-2016-05-18-1.log
05/18/2016  02:03 PM        24,619,048 MLMServices-2016-05-18-2.log
05/18/2016  08:05 PM        25,667,655 MLMServices-2016-05-18-3.log
05/19/2016  09:18 AM        25,786,502 MLMServices-2016-05-19-1.log
05/19/2016  02:00 PM        26,259,036 MLMServices-2016-05-19-2.log
05/19/2016  05:52 PM        26,593,795 MLMServices-2016-05-19-3.log
05/19/2016  06:26 PM        26,671,744 MLMServices-2016-05-19-4.log
05/20/2016  03:30 PM        27,191,829 MLMServices-2016-05-20-1.log
05/20/2016  05:27 PM        28,240,467 MLMServices-2016-05-20-2.log
05/23/2016  06:10 PM        29,204,271 MLMServices-2016-05-23-1.log
05/24/2016  09:55 AM        29,338,523 MLMServices-2016-05-24-1.log
05/24/2016  10:31 AM        29,441,164 MLMServices-2016-05-24-2.log
05/24/2016  12:04 PM        29,556,676 MLMServices-2016-05-24-3.log
05/24/2016  12:05 PM        29,577,736 MLMServices-2016-05-24-4.log
05/20/2016  05:27 PM        29,734,763 MLMServices.log

这不是我想要的行为。我只想将每个日志文件限制为1MB,并且我希望最多保留30个日志文件。在配置中哪里出错了?

提前致谢

编辑:我实际上在weblogic.xml中指定了log4j2

<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app 
       http://xmlns.oracle.com/weblogic/weblogic-web-app/1.7/weblogic-web-app.xsd">
    <wls:context-root>XXXXXX</wls:context-root>
    <wls:library-ref>
        <wls:library-name>jax-rs</wls:library-name>
        <wls:specification-version>2.0</wls:specification-version>
        <wls:exact-match>false</wls:exact-match>
    </wls:library-ref>
    <wls:container-descriptor>
        <wls:prefer-application-packages>
            <wls:package-name>org.slf4j</wls:package-name>
            <wls:package-name>log4j</wls:package-name>
        </wls:prefer-application-packages>
    </wls:container-descriptor>
</wls:weblogic-web-app>

1 个答案:

答案 0 :(得分:0)

您应该检查您的应用程序之外的某些内容是否正在访问MLMServices.log。在Windows上,如果无法获得独占锁,则文件重命名和删除将失败。