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

  • Home
  • SEARCH
  • 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 6168293
In Process

The Archive Base Latest Questions

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

Sorry for the log4net newb quesiton, this looks like a common setup, but I

  • 0

Sorry for the log4net newb quesiton, this looks like a common setup, but I cannot find an example.

I am trying to get the following setup with my log4net config:

Two appenders:

  • File_Appender -> log4net.Appender.RollingFileAppender
  • Smtp_Appender -> log4net.Appender.SmtpAppender
    (evaluator threshold set to ERROR)

Many loggers:

  • All loggers (root) -> INFO,WARN,ERROR -> File_Appender
  • All loggers (root) -> ERROR -> Smtp_Appender
  • Specific loggers -> DEBUG -> File_Appender
  • Specific loggers -> INFO -> Smtp_Appender

I am not sure how to configure the “root” logger to log different levels to different appenders (I don’t want to explicitly configure each logger to log errors to a Smtp_Appender).

  • 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-23T22:39:46+00:00Added an answer on May 23, 2026 at 10:39 pm

    I ended up doing my own appender filter, which allows setting a lower matching level for explicitly specified loggers:

    public class MultipleLevelFilter : LevelMatchFilter
    {
        public MultipleLevelFilter()
        {
            LevelToMatchForSpecificLoggers = Level.Fatal;
            _specificLoggers = new string[0];
        }
    
        /// <summary>
        /// Gets or sets the level to match for loggers
        /// specified in the <see cref="SpecificLoggers"/> property.
        /// </summary>
        /// <value>The level to match for specific loggers.</value>
        public Level LevelToMatchForSpecificLoggers { get; set; }
    
        private string[] _specificLoggers;
        /// <summary>
        /// Gets or sets a comma separated list of "specific" loggers.
        /// For these loggers, <see cref="LevelToMatchForSpecificLoggers"/>
        /// property is checked to see whether they should be logged.
        /// </summary>
        /// <value>The specific loggers.</value>
        public string SpecificLoggers 
        {
            get { return string.Join(",", _specificLoggers); }
            set
            { 
                _specificLoggers = value.Split(',').Select(s=>s.Trim()).ToArray();
            }
        }
    
        /// <summary>
        /// Tests if filter matches the specified logging event.
        /// </summary>
        /// <param name="loggingEvent">the event to filter</param>
        public override FilterDecision Decide(LoggingEvent loggingEvent)
        {
            // if base.LevelToMatch is matched, always match
            if (loggingEvent.Level >= LevelToMatch)
               return AcceptOnMatch ? FilterDecision.Accept : FilterDecision.Deny; 
    
            // if specific level is matched, check if logger name matches
            if (loggingEvent.Level >= LevelToMatchForSpecificLoggers)
            {
                string name = loggingEvent.LoggerName;
                for (int i = 0; i < _specificLoggers.Length; i++)
                    if (name == _specificLoggers[i])
                        return AcceptOnMatch ?
                            FilterDecision.Accept : FilterDecision.Deny;
            }
    
            // continue with next filter
            return FilterDecision.Neutral;
        }
    }
    

    Usage:

    <appender name="Smtp_Appender" 
         type="Ster.Log4Net.DelayedSendSmtpAppender">
    
      <!-- ... common properties (from, to, etc) -->
    
      <!-- our custom filter -->      
      <filter type="MyNamespace.MultipleLevelFilter">
    
        <!-- this level is ALWAYS matched -->
        <levelToMatch value="ERROR" />
    
        <!-- this level is matched only for specific loggers -->
        <levelToMatchForSpecificLoggers value="INFO" />
    
        <!-- these are the "specific" loggers (comma separated) -->
        <specificLoggers value="SomeLogger, SomeOtherLogger" />
    
      </filter>
      <!-- always end the filter chain with DenyAll -->
      <filter type="log4net.Filter.DenyAllFilter" />
    
    </appender>
    
    <root>
      <priority value="INFO" />
      <appender-ref ref="File_Appender" />
      <appender-ref ref="Smtp_Appender" />
    </root>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for this simple question, but I can't solve it... There is an example:
Sorry, I know this question is easy, but I don't know how to get
sorry for the dummy question but I cannot find a simple and clean way
Sorry for asking this but, I cant found a solution that will get this
Sorry for the simple question, but I'm trying to find an elegant way to
Sorry if this sounds like a really stupid question, but I need to make
Sorry if this question's been asked before, but I can't seem to find an
Sorry for question but I can't find answer anywhere on internet. I couldn't find
Sorry but I am not sure how to ask this question but I am
Sorry if this question seems stupid, but it's stumped me for a couple days,

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.