为元素 RollingFile 提供的参数无效:字段“filePattern”具有无效值“null”,字段“policy”具有无效值“null”

问题描述 投票:0回答:0

Log4j

1.2.17
到 Log4j
2.20.0
版本迁移。

log4j2.xml - XML 配置文件

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Appenders>
        <!-- RollingFile filePattern="logs/$${date:yyyy-MM}/app-%d{yyyy-MM-dd}-%i.log.gz" is also not set here. I do want the log files not be rolled automatically. -->
        <RollingFile name="RollingFile"
                     fileName="logs/app.log">
            <PatternLayout>
                <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
            </PatternLayout>
<!--      I do not want to specify any Policies. So, Policies are not set here      -->
<!--            <Policies>-->
<!--                <SizeBasedTriggeringPolicy size="10 MB"/>-->
<!--            </Policies>-->
        </RollingFile>
    </Appenders>
    <Loggers>
        <Root level="trace">
            <AppenderRef ref="RollingFile"/>
        </Root>
    </Loggers>
</Configuration>

RollingFile ‘filePattern’ 属性

据我所知,RollingFile 的“filePattern”属性是可选的。如果不指定 filePattern 属性,则日志文件不会自动滚动,也不会被删除。 RollingFile appender 有一个可选的 filePattern 属性,允许您指定日志文件的名称模式。此名称模式可用于根据大小、日期或其他条件滚动日志文件。如果不指定 filePattern,日志文件将保持相同的名称并且不会滚动。

RollingFile 策略元素。

据我所知,Policies 元素是可选的。如果您不指定 Policies 元素,那么日志文件将不会自动滚动并且不会被删除。 如果您不指定 Policies 元素,那么日志文件将不会自动滚动,也不会被删除。

但是,我发现以下异常。如何解决?

org.apache.logging.log4j.core.config.ConfigurationException: Arguments given for element RollingFile are invalid: field 'filePattern' has invalid value 'null', field 'policy' has invalid value 'null'
xml java-8 log4j log4j2
© www.soinside.com 2019 - 2024. All rights reserved.