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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:13:49+00:00 2026-06-05T05:13:49+00:00

I want to be able to specify multiple smtp server host addresses and implement

  • 0

I want to be able to specify multiple smtp server host addresses and implement a logic whereby if email using one smtp server fails, it tries to send using the next smtp server address. Is it possible using log4net. Can we override some functions of log4net and implement our own logic in it to send emails?

<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
  <to value="group@ivp.in" />
  <from value="uname@ivp.in" />
  <subject>Error Notification</subject>
  **<smtpHost value="10.0.0.12, 10.0.0.13" />**
  <authentication value="None" />
  <port value="25" />
  <bufferSize value="1" />
  <EnableSsl value="false"/>
  <lossy value="true" />
  <evaluator type="log4net.Core.LevelEvaluator">
    <threshold value="ERROR"/>
  </evaluator>
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%newline%date [%thread] %level %logger - %message%newline%newline%exception" />
  </layout>
</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-06-05T05:13:51+00:00Added an answer on June 5, 2026 at 5:13 am

    It is possible only if you implement custom SmtpAppender.

    I have copied CustomSmtpAppender code from Log4net sourcecode Examples. hopefullly this will help you.

    don’t forget to refer CustomSmtpAppender in your app config

    using System;
    using System.IO;
    using System.Web.Mail;
    
    using log4net.Layout;
    using log4net.Core;
    using log4net.Appender;
    
    namespace SampleAppendersApp.Appender
    {
        /// <summary>
        /// Simple mail appender that sends individual messages
        /// </summary>
        /// <remarks>
        /// This SimpleSmtpAppender sends each LoggingEvent received as a
        /// separate mail message.
        /// The mail subject line can be specified using a pattern layout.
        /// </remarks>
        public class SimpleSmtpAppender : AppenderSkeleton
        {
            public SimpleSmtpAppender()
            {   
            }
    
            public string To 
            {
                get { return m_to; }
                set { m_to = value; }
            }
    
            public string From 
            {
                get { return m_from; }
                set { m_from = value; }
            }
    
            public PatternLayout Subject 
            {
                get { return m_subjectLayout; }
                set { m_subjectLayout = value; }
            }
    
            public string SmtpHost
            {
                get { return m_smtpHost; }
                set { m_smtpHost = value; }
            }
    
            #region Override implementation of AppenderSkeleton
    
            override protected void Append(LoggingEvent loggingEvent) 
            {
                try 
                {     
                    StringWriter writer = new StringWriter(System.Globalization.CultureInfo.InvariantCulture);
    
                    string t = Layout.Header;
                    if (t != null)
                    {
                        writer.Write(t);
                    }
    
                    // Render the event and append the text to the buffer
                    RenderLoggingEvent(writer, loggingEvent);
    
                    t = Layout.Footer;
                    if (t != null)
                    {
                        writer.Write(t);
                    }
    
                    MailMessage mailMessage = new MailMessage();
                    mailMessage.Body = writer.ToString();
                    mailMessage.From = m_from;
                    mailMessage.To = m_to;
    
                    if (m_subjectLayout == null)
                    {
                        mailMessage.Subject = "Missing Subject Layout";
                    }
                    else
                    {
                        StringWriter subjectWriter = new StringWriter(System.Globalization.CultureInfo.InvariantCulture);
                        m_subjectLayout.Format(subjectWriter, loggingEvent);
                        mailMessage.Subject = subjectWriter.ToString();
                    }
    
                    if (m_smtpHost != null && m_smtpHost.Length > 0)
                    {
                        SmtpMail.SmtpServer = m_smtpHost;
                    }
    
                    SmtpMail.Send(mailMessage);
                } 
                catch(Exception e) 
                {
                    ErrorHandler.Error("Error occurred while sending e-mail notification.", e);
                }       
            }
    
            override protected bool RequiresLayout
            {
                get { return true; }
            }
    
            #endregion // Override implementation of AppenderSkeleton
    
            private string m_to;
            private string m_from;
            private PatternLayout m_subjectLayout;
            private string m_smtpHost;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I want to be able to specify multiple different sources for my FullCalendar
I have a situation where I want users to be able to specify a
I've a WPF toolkit chart which I want to be able to both specify
I'm using LaTeX and BibTeX for an article, and I want to able to
I'm writing a Makefile for C. I want be able to specify different programs
I want to be able to specify the file name stem for the log
Basically, I want to be able to specify the height of my li element
I want to be able to specify the location in both where to scan
I have some jquery code that i want to able to drag, drop, clone
I have a messages table that auto increments and I simply want to able

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.