Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6001633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:51:45+00:00 2026-05-23T00:51:45+00:00

When ConsoleAppender is static, I get the following error from log4j: log4j:ERROR Attempted to

  • 0

When ConsoleAppender is static, I get the following error from log4j:

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

Example code:

import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
public class Logging {
    private static final PatternLayout layout = new PatternLayout("[%d{dd MMM yyyy HH:mm:ss}] [%t] %-6r %-5p %m\n");
    private static final ConsoleAppender consoleAppender = new ConsoleAppender(layout);
    private Logger logger;
    private String filterClass;
    private boolean logFlag = false;

    public LoggingExample(Class c) {
        logger = Logger.getLogger(c);
        logger.setAdditivity(false);
        logger.removeAllAppenders();
        logger.addAppender(consoleAppender);
        consoleAppender.activateOptions();
        filterClass = c.getName();
    }

    public log() {
        logger.info("this doesn't work when ConsoleAppender is static!");
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:51:46+00:00Added an answer on May 23, 2026 at 12:51 am

    That happens because removeAllAppenders() removes and closes all the appenders and the underlying writers. Your console appender’s writer is then also closed when you do it because a console appender is already attached to the logger by default if you ever create more than one instance of LoggingExample.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following log4j.xml configuration: <log4j:configuration> <appender name = CONSOLE class = org.apache.log4j.ConsoleAppender>
I have the following on my log4j.properties log4j.rootLogger = debug, stdout, fileLog log4j.appender.stdout =
I have the following logback.xml file: <configuration debug=true> <appender name=STDOUT class=ch.qos.logback.core.ConsoleAppender> <encoder> <pattern>%d{HH:mm:ss.SSS} [%thread]
My log4j.properties file - log4j.rootLogger=INFO, stdout # =============== console output appender ===================== log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
I have the following code: private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); XmlConfigurator.Configure(new FileInfo(log4net.config));
Which is the quickest appender for log4Net apart from ConsoleAppender?
i am using log4j and my configuration is as follows: log4j.rootLogger=OFF, stdout, rootLog log4j.appender.stdout=org.apache.log4j.ConsoleAppender
I want to programmatically create a new log4j ConsoleAppender and add it as an
I am trying to produce a proof of concept shipping logging from Log4J through
I'm trying to figure out how to get log4j working in my project. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.