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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:28:33+00:00 2026-06-06T06:28:33+00:00

I am using log4net. When Application gives an error, I want to send e-mail

  • 0

I am using log4net.

When Application gives an error, I want to send e-mail just for errors. How should I do that ?

My Config File :

<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
  </configSections>
  <log4net>
    <appender name="SMTPAppender" type="log4net.Appender.SMTPAppender">
      <authentication value="Basic" />
      <to value="xxx@xxx" />
      <from value="yyy@yyy" />
      <username value="user" />
      <password value="pass" />
      <subject value="ERROR" />
      <smtpHost value="host" />
      <port value="25" />
      <lossy value="true" />
      <evaluator type="log4net.Core.LevelEvaluator">
        <threshold value="WARN" />
      </evaluator>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%newline%date [%thread] %-5level %logger %newline %message%newline%newline%newline" />
      </layout>
    </appender>
    <root>
      <level value="INFO"></level>
    </root>
    <logger name="SMTPAppender">
      <level value="INFO"></level>
      <appender-ref ref="SMTPAppender"></appender-ref>
    </logger>
  </log4net>
</configuration>

I am trying to test in NUnit:

[TestFixture]
public class TestClass
{
    [Test]
    public void Test()
    {
        ILog logger = LogManager.GetLogger(typeof(TestClass));
        logger.Error("test mail");
    }
}

I am probably doing something wrong.

EDIT:

<logger name="Yuartz.Tests.TestClass">
  <level value="INFO"></level>
  <appender-ref ref="SMTPAppender"></appender-ref>
</logger>
namespace Yuartz.Tests
{
    using log4net;
    using log4net.Config;

    [TestFixture]
    public class TestClass
    {
        [Test]
        public void Test()
        {
            XmlConfigurator.Configure();
            var logger = LogManager.GetLogger("SMTPAppender");
            logger.Error("test mail");
            logger.Info("test mail");
        }
    }
}
  • 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-06T06:28:34+00:00Added an answer on June 6, 2026 at 6:28 am

    In your example you use the full name of the type (TestClass) to retrieve your logger. It will use this name to resolve the logger or create a new one when not found.

    ILog logger = LogManager.GetLogger(typeof(TestClass));
    

    If you want this line of code to return the SMTPAppender logger, then you need to rename it in the config as follows:

    <logger name="Yuartz.Tests.TestClass">
        ...
    </logger>
    

    If you don’t want to change the configuration then you need to retrieve your logger by its actual name. The following returns the logger named “SMTPAppender”.

    var logger = LogManager.GetLogger("SMTPAppender");
    

    My advice is to just change the name in the configuration and keep retrieving the logger by type as you currently do.

    Also make sure that you read your configuration.

    log4net.Config.XmlConfigurator.Configure();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using log4net within a Console Application. My configuration file allow me to
Currently my application is using log4net to log errors, the web.config for this is
We have an application that logs using log4net. But we would like to delete
I am using log4net for logging my asp.net application. However the log file is
My application writes a log file (currently using log4net ). I'd like to setup
I am using log4net to log the errors. Currently I downloaded the file log4net.dll
i want to log an asp.net , framework 4.0 web application. i'm using log4net
I have just begun working on a C# application (using log4net). I'm supposed to
I'm using Log4Net and logging everytime my ASP.NET-Application throws an error: protected void Application_Error(object
I want to Implement Logging future using log4net for my asp.net mvc application.. Can

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.