2

我将 log4j1.2.17 与我的 Spring Web 应用程序(Spring 3.2.1)一起使用。我间歇性地遇到以下问题。有时它来自启动本身,有时来自请求处理。以下是堆栈跟踪。

log4j:ERROR Failed to flush writer,
java.io.IOException: The handle is invalid
    at java.io.FileOutputStream.writeBytes(Native Method)
    at java.io.FileOutputStream.write(Unknown Source)
    at sun.nio.cs.StreamEncoder.writeBytes(Unknown Source)
    at sun.nio.cs.StreamEncoder.implFlushBuffer(Unknown Source)
    at sun.nio.cs.StreamEncoder.implFlush(Unknown Source)
    at sun.nio.cs.StreamEncoder.flush(Unknown Source)
    at java.io.OutputStreamWriter.flush(Unknown Source)
    at org.apache.log4j.helpers.QuietWriter.flush(QuietWriter.java:59)
    at org.apache.log4j.WriterAppender.subAppend(WriterAppender.java:324)
    at org.apache.log4j.RollingFileAppender.subAppend(RollingFileAppender.java:276)
    at org.apache.log4j.WriterAppender.append(WriterAppender.java:162)
    at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
    at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)
    at org.apache.log4j.Category.callAppenders(Category.java:206)
    at org.apache.log4j.Category.forcedLog(Category.java:391)
    at org.apache.log4j.Category.log(Category.java:856)
    at org.apache.commons.logging.impl.Log4JLogger.info(Log4JLogger.java:199)

当我调试时,文件句柄似乎已经关闭。有一次,当我在异常之前进行测试时,我从 log4j 收到以下消息

log4j:Finalizing appender named [stdout].
log4j:Finalizing appender named [logfile].

不知道为什么当应用程序仍在使用它时它会被最终确定。

下面是我的 log4j xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d %p [%c] -  %m%n" />
    </layout>
</appender>

<appender name="logfile" class="org.apache.log4j.RollingFileAppender">
    <param name="File"
        value="E:/logs/bizscore.log" />
    <param name="MaxFileSize" value="5000KB" />
    <param name="MaxBackupIndex" value="3" />
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d %p [%c] -  %m%n" />
    </layout>
</appender>


<logger name="org.apache.commons">
    <level value="INFO" />
</logger>



<logger name="org.hibernate">
    <level value="INFO" />
</logger>

<logger name="org.springframework">
    <level value="INFO" />
</logger>

<root>
    <priority value="info" />
    <appender-ref ref="stdout" />
    <appender-ref ref="logfile" />
</root>

</log4j:configuration>

任何指针都会有很大帮助。谢谢。

4

0 回答 0