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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:14:26+00:00 2026-06-10T02:14:26+00:00

Is there a way to constraint log4n appender to log messages based on host

  • 0

Is there a way to constraint log4n appender to log messages based on host name? I want to enable logger only on production machines and disable logging n development machines.

I know that there is an easy way to log host name with property: %property{log4net:HostName}, then I could filter logged messages by this, but I want to use smtp appender and send logged messages via email and I would like to reduce number of sent emails.

  • 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-10T02:14:27+00:00Added an answer on June 10, 2026 at 2:14 am

    I found solution using custom filter:

    public class HostFilter : FilterSkeleton
    {
        public string AllowedHostsNames { get; set; }
        private IList<string> HostNamesList
        {
            get
            {
                if (string.IsNullOrEmpty(AllowedHostsNames))
                    return new List<string>();
    
                return AllowedHostsNames
                    .Split(',')
                    .Select(n => n.ToUpper().Trim())
                    .ToList();
            }
        }
    
        public override FilterDecision Decide(LoggingEvent loggingEvent)
        {
            var names = HostNamesList;
            if (names.Contains(Environment.MachineName))
                return FilterDecision.Accept;
    
            return FilterDecision.Deny;
        }
    }
    
    
    <appender name="SomeAppender" type="log4net.Appender.SmtpAppender">
      <to value="" />
      <from value="" />
      <subject value="" />
      <smtpHost value="" />
      <authentication value="Basic" />
      <port value="25" />
      <username value="" />
      <password value="" />
      <bufferSize value="10" />
      <lossy value="false" />
      <layout type="log4net.Layout.PatternLayout">
         <conversionPattern value="%newline%date [%thread] %-5level %logger - %message%newline%newline%newline" />
      </layout>
      <filter type="Logging.HostFilter, AssemblyName">
        <allowedHostsNames value="host1, host2, host3" />
      </filter>
    </appender>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In MSSQL is there a way to specify a name for a PK constraint
i want to define Hayt class constraint for hede method. is there a way
Is there a way to enforce constraint checking in MSSQL only when inserting new
Is there a way to constraint a generic type to only integral type? In
Is there a way to implement a CHECK constraint that checks a value against
I was wondering if there exists any way to set a constraint on the
Is there a way to add a constraint in SQL Server 2008 that will
Is there a way to add a constraint to an attached dependency property so
Is there a way to create a Generic Method that uses the new() constraint
Is there a way to set a SQL constraint for a numeric field that

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.