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 8492017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:35:53+00:00 2026-06-10T22:35:53+00:00

Is it possible to determine if an appender is disabled (i.e. <level value=Off> )?

  • 0

Is it possible to determine if an appender is disabled (i.e. <level value="Off">)?

I would like to have a global flag that determines if my appender is enabled:

public static bool isAppenderEnabled = /*...*/;

If the appender is enabled, then I would log stuff:

if(isAppenderEnabled)
{
    MyAppender.Warn("****************************************");
    MyAppender.Warn("Warning title!");
    MyAppender.Warn(String.Format("Some warning message! A:{0}, B:{1}, C:{2}, D:{3}", 0, 1, 2, 3));
    MyAppender.Warn("****************************************");
}

It’s important to have the isAppenderEnabled flag, because I would be saving a lot of CPU time when the appender is disabled due to the fact that I’m not constructing all of those strings. What’s the best/easiest way to check if an appender is turned off?

P.S.
I’ve tried the MyAppender.Logger.IsEnabledFor(log4net.Core.Level.Off);, however, if I set the log level to Warn it always returns true for Off (basically, it always says the logger is disabled), so that doesn’t work.

  • 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-06-10T22:35:54+00:00Added an answer on June 10, 2026 at 10:35 pm

    The recommended way of doing is, isn’t to have a global flag to say whether logging is enabled, but rather to test the actual logging level of a per call basis,
    eg

    if (MyAppender.IsWarnEnabled)
    {
        MyAppender.Warn(String.Format("Some warning message! A:{0}, B:{1}, C:{2}, D:{3}", 0, 1, 2, 3));
    }
    

    …

    if (MyAppender.IsDebugEnabled)
    {
        MyAppender.Debug(String.Format("Some debug info! A:{0}, B:{1}, C:{2}, D:{3}", 0, 1, 2, 3));
    }
    

    …

    if (MyAppender.IsErrorsEnabled)
    {
        MyAppender.Error(String.Format("Some error message! A:{0}, B:{1}, C:{2}, D:{3}", 0, 1, 2, 3));
    }
    

    The advantage of this method is that you can set and leave your logging to Level.Error or Level.Fatal without constructing all the strings in your warn/debug and info messages.

    Having said that, it is your choice. To answer your question, the reason MyAppender.Logger.IsEnabledFor(log4net.Core.Level.Off);
    doesn’t work, is that MyAppender.Logger.IsEnabledFor(x) will return true if the level is set to x or higher. Hence I would expect this call to always return true.

    The next level up is (AFAIK) log4net.Core.Level.Emergency so could check for that, but as that level isn’t commonly used, you could also check for log4net.Core.Level.Fatal

    MyAppender.IsFatalEnabled is just a property wrapper for MyAppender.Logger.IsEnabledFor(log4net.Core.Level.Fatal) ,

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

Sidebar

Related Questions

Is it possible to determine the byte, or bytes, that have changed from a
Possible Duplicate: Determine the parent process of the current app I would like to
Is it possible to determine a specific file's fragmentation status (that is, the amount
Is it possible to determine the interfaces that can be used to cast a
Possible Duplicate: Determine a string's encoding in C# Many text editorsr (like Notepad++) can
It's possible to determine memory usage (according to Jon Skeet's blog) like this :
Would it be possible to determine if a webpage was accessed from the result
I wonder, if it possible to determine, that user left certain tab. For example,
Possible Duplicate: Determine framework (CLR) version of assembly I have a library/DLL file which
Is it possible to determine that I can safely pull from a new remote

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.