Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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?

XML
<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
      <to value="group@ivp.in" />
      <from value="uname@ivp.in" />
      <subject>Error Notification</subject>
      <smtpHost value="smtp.gmail.com" />
      <authentication value="Basic" />
      <port value="587" />
      <username value="uname@company.com" />
      <password value="" />
      <bufferSize value="1" />
      <EnableSsl value="true"/>
      <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>


Thanks,
Pankaj
Posted
Updated 6-Jun-12 21:18pm
v2

1 solution

One approach you can take -- though there are many solutions -- is to implement Common.Logging 2.0. This will give you pretty much the basic logging interface without any logging implementation. Then through Common.Logging configuration you can tell it what to use.

Via this mechanism you can
a) get all calls for logging written before addressing logging specifics
b) if you find you need to do custom logging, your code gets configured to be
called by Common.Logging and if you can use Log4Net for 90% of your tasks
then just pass through the calls to Log4Net.

In this fashion you can write you own code to do any custom logging you need to do. I did this with our environment because we were creating a unique log entry in the database providing a ton more info than what log4net was providing. Common.Logging provides you with either stubs into various popular logging tools, or the interfaces to do your own. It took about 1 hour of coding to have my logging facility called by everyone ... including NCommon's baked in log calls.
 
Share this answer
 
Comments
Pankaj Chamria 7-Jun-12 3:21am    
Thanks. But am hoping for a log4net solution to this problem without having to use two logging frameworks. Of course if there is none then I may resort to the Logging Application Block in Microsoft's Enterprise Library.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900