log4j:ERROR Attempted to append to closed appender named [..]

I got the same error:

log4j:ERROR Attempted to append to closed appender named [rollingFileAppender].

In my log4j.xml

I have two loggers with the same name like below

<logger name="java.sql.PreparedStatement" additivity="false">
    <level value="INFO"/>
    <appender-ref ref="rollingFileAppender"/>
</logger>

 <logger name="java.sql.PreparedStatement">
    <level value="INFO"/>
    <appender-ref ref="rollingFileAppender"/>
</logger>

I removed the duplicate, it worked.


I've answered similar question here: https://stackoverflow.com/a/9973283/340290

In my case, I've two log4j.properties available to the Log4J: one via placing it in classpath and other being loaded programmatically (using PropertyConfigurator.configure(..)).

And in the two files, I've ConsoleAppender registered with same name stdout and used for same category twice (one per each properties file). Removing config or the properties file solved my issue.


One could overwrite the configuration using:

BasicConfigurator.resetConfiguration();
PropertyConfigurator.configure(props);

Tags:

Log4J