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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:14:53+00:00 2026-06-03T00:14:53+00:00

Currently my application is using log4net to log errors, the web.config for this is

  • 0

Currently my application is using log4net to log errors, the web.config for this is as followed:

<log4net>
    <appender name="FileAppender" type="log4net.Appender.RollingFileAppender">
      <file type="log4net.Util.PatternString" value="../../logs/gateway_%date{yyyyMMdd}.log" />
      <appendToFile value="true" />
      <rollingStyle value="Date" />
      <datePattern value="yyyyMMdd" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] – %message%newline" />
      </layout>
    </appender>
    <root>
      <level value="DEBUG" />
      <appender-ref ref="RollingLogFileAppenderOutput" />
    </root>
  </log4net>

However, the client now wants each error to be emailled to them.

What is the easiest way to do this, can you do it within the web.config file?

  • 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-03T00:14:54+00:00Added an answer on June 3, 2026 at 12:14 am

    You should use SmtpAppender

    <appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
        <to value="to@example.com" />
        <from value="from@example.com" />
        <subject value="test logging message" />
        <smtpHost value="SMTPServer.example.com" />
        <bufferSize value="512" />
        <lossy value="true" />
        <evaluator type="log4net.Core.LevelEvaluator">
            <threshold value="WARN"/>
        </evaluator>
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%newline%date [%thread] %-5level %logger [%property{NDC}] - %message%newline%newline%newline" />
        </layout>
    </appender>
    
    <logger name="ErrorLogger">
        <level value="Error" />
        <appender-ref ref="FileAppender" />
    </logger>
    <logger name="EmailLogger">
        <level value="Error" />
        <appender-ref ref="SmtpAppender" />
    </logger>
    

    In order to send emails only for an specific error you could do something like this

    try
    {
      // your logic
    }
    catch (MySpecificException ex)
    {
       // I only send emails for exception of type MySpecificException
       LogManager.GetLogger("EmailLogger").Error(ex);
    }
    catch (Exception ex)
    {
       // Just log to a file for the rest
       LogManager.GetLogger("ErrorLogger").Error(ex);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using log4net to log the errors. Currently I downloaded the file log4net.dll
My application writes a log file (currently using log4net ). I'd like to setup
I'm currently developing a web application using Struts2 framework. This application requires to dynamically
I'm currently using log4net in my ASP.NET MVC application to log exceptions. The way
I'm using Log4Net to handle logging in my WPF application. Currently, the logger is
Currently developing an application using the newest version of symfony, obtained through PEAR. This
we are currently working on a new web application using Java and MySql. We
I am currently working on a JAVA web application using JSF, Facelets, JSTL and
I am currently working on securing a web application using spring-security 3.0. I have
Currently I'm develping a web application using Zend framework. My problem is that 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.