使用log4net的多个smtphost地址 [英] Multiple smtphost addresses using log4net

查看:219
本文介绍了使用log4net的多个smtphost地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够指定多个smtp服务器主机地址,并实现一种逻辑,如果使用一个smtp服务器的电子邮件失败,它将尝试使用下一个smtp服务器地址进行发送.是否可以使用log4net.我们可以覆盖log4net的某些功能并在其中实现自己的逻辑来发送电子邮件吗?

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="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>



谢谢,
Pankaj



Thanks,
Pankaj

推荐答案

您可以采用的一种方法(尽管有很多解决方案)是实现Common.Logging 2.0.这将为您提供基本的日志记录界面,而无需任何日志记录实现.然后通过Common.Logging配置,您可以告诉它使用什么.

通过这种机制,您可以
a)在解决日志记录细节之前获取所有的日志记录调用
b)如果发现需要进行自定义日志记录,则将代码配置为
由Common.Logging调用,是否可以使用Log4Net完成90%的任务
然后只需通过对Log4Net的调用即可.

您可以通过这种方式编写自己的代码,以执行所需的任何自定义日志记录.我是在我们的环境中执行此操作的,因为我们正在数据库中创建一个唯一的日志条目,它提供的信息比log4net提供的信息多得多. Common.Logging为您提供了各种流行的日志记录工具的存根,或者为您提供了自己的界面.经过大约1个小时的编码,每个人都调用了我的日志记录功能...包括NCommon的日志调用.
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.


这篇关于使用log4net的多个smtphost地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆