log4j2不使用rollingFile追加器写入日志文件 [英] log4j2 not writing to the log file with rollingFile appenders

查看:230
本文介绍了log4j2不使用rollingFile追加器写入日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新用户,使用log4j

Hi i am new using log4j

我正在尝试配置xml以使用and附加程序将那些日志记录发送到日志文件中,嗯,附加程序工作正常,因此我想使用附加程序,以便它每天都会清除日志文件,但是在首次创建时会清除该日志文件日志文件,它不会在所创建的文件中写入任何日志消息,所以我来这里是为了寻求建议

I am trying to configure the xml to send those logging into the log file using the and appender, well, the appender works fine so i want to use appender so that it will clear the log file daily, but when it first created the log file, it doesn't write any log message into the file created by , so i come here to get some advise

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="FATAL" >

<Appenders>
    <Console name="Console" target="SYSTEM_OUT">
        <PatternLayout pattern="${pattern}" />
    </Console>

    <RollingFile name="rollingfile" fileName="rolling.log"
    filePattern="rolling-%d{MM-dd-yyyy}.log">
        <PatternLayout pattern="${pattern}" />
        <Policies>
              <TimeBasedTriggeringPolicy interval="1" modulate="true" />
              <SizeBasedTriggeringPolicy size="10 MB" />
        </Policies>
    </RollingFile>

    <File name="file" fileName="test2.log">
        <PatternLayout pattern="${pattern}" />
    </File>     

</Appenders>


<Loggers>   
    <Root level="trace" >
        <AppenderRef ref="Console" />
        <AppenderRef ref="rollingfile" />
        <AppenderRef ref="file" />
    </Root>
</Loggers>
</Configuration>

推荐答案

您有AppenderRef="rolling",但您的Appender名为"rollingfile".这些需要匹配.

You have AppenderRef="rolling", but your Appender is named "rollingfile". These need to match.

此外,log4j可能会发出警告,说明配置存在问题.我建议您在配置开始时指定<Configuration status="WARN" >而不是FATAL,以便可以看到这些警告.

Also, log4j probably issues a warning that there is a problem with the configuration. I recommend you specify <Configuration status="WARN" > at the start of your config instead of FATAL so that you can see these warnings.

可能需要指定${sys:pattern}才能读取系统属性.代替${pattern}变量,首先尝试使用类似%d %p [%t] %m%n的显式模式.

It may be that you need to specify ${sys:pattern} to read the system property. Instead of the ${pattern} variable, first try an explicit pattern like %d %p [%t] %m%n.

这篇关于log4j2不使用rollingFile追加器写入日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆