1

我的 log4j 记录器不想使用log4j.xml要配置的文件。该文件位于src文件夹中,如下所示:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration>
    <appender name="ROLLING" class="org.apache.log4j.RollingFileAppender">
        <param name="File" value="C:\debug\myproject\logfile.log" />
        <param name="MaxFileSize" value="10024KB" />
        <param name="MaxBackupIndex" value="5" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%-5p %d{dd-MM HH:mm:ss,SSS} (%F:%M:%L)  -%m%n" />
        </layout>
        <filter class="org.apache.log4j.varia.LevelRangeFilter">
            <param name="LevelMin" value="DEBUG" />
            <param name="LevelMax" value="FATAL" />
        </filter>
    </appender>
    <root>
        <level value="DEBUG" />
        <appender-ref ref="ROLLING" />
    </root>
</log4j:configuration>

但是logfile.log仍然是空的,并且DEBUG控制台中没有行。

注意:这是一个基于 JBoss 7.1.0 并使用 Struts2 的 Java EE 项目。

4

3 回答 3

1

The following answer is not entirely mine. It was posted in the question itself by the OP, so I'm moving it into this community wiki answer.


I resolved it by explicitely configuring the logging configuration.

Note that you won't be able to change the configuration at runtime if you configure it using a file.

For more information, see: https://docs.jboss.org/author/display/AS71/How+To#HowTo-HowdoIuselog4j.propertiesorlog4j.xmlinsteadofusingtheloggingsubsystemconfiguration%3F

于 2014-07-02T17:04:49.887 回答
0

确保 log4j.xml 文件位于/WEB-INF/classesWeb 应用程序的目录中。

于 2013-02-22T16:00:18.453 回答
0

问题出在日志文件上。如果您使用绝对文件名,请确保将反斜杠替换为斜杠。例如

<param name="File" value="C:/debug/myproject/logfile.log" /> 
于 2013-02-22T18:58:25.333 回答