防止log4net通过SMTP发送重复的问题 [英] Prevent log4net to send duplicate issues via SMTP

查看:110
本文介绍了防止log4net通过SMTP发送重复的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经使用SMTP在logira和Jira之间建立了桥接.

we have bridged our log4net with Jira using SMTP.

现在,我们担心由于该站点是公共站点,如果我们在生产环境中遇到很多问题,Jira服务器会发生什么情况.

Now we are worried that since the site is public what could happen to the Jira server if we get alot of issues in the production environment.

我们已经对严重"和致命"进行了过滤,但是我们希望在log4net上看到一些算盘服务,或者希望使用普通过滤器来识别重复的问题并阻止通过电子邮件发送问题.最好不必更改错误报告代码,因此最好使用配置解决方案.

We have already filtered on Critical and Fatal, but we want to see either some acumulator service on log4net or a plain filter which identifies repeating issues and prevents them from being sent via Email. Preferably without having to change the error reporting code, so a config solution would be best.

我猜想将日志转储到数据库中,然后创建一个单独的侦听器,一些智能代码将是(昂贵的)替代方案.

I guess dumping the log into a db and then create a separate listener some smart code would be a (pricy) alternative.

推荐答案

也许

Maybe this is sufficient for your requirements:

它基本上限制了在给定时间范围内发送的电子邮件数量.我认为根据您的需求对其进行自定义应该很容易.我做了类似的事情,甚至在一定时间范围内丢弃了消息:

it basically limits the number of emails that are sent in a given time span. I think it should be quite easy to customize this to your needs. I did something similar that even discards messages within a certain time span:

public class SmtpThrottlingAppender : SmtpAppender
{
    private DateTime lastFlush = DateTime.MinValue;
    private TimeSpan flushInterval = new TimeSpan(0, 5, 0);

    public TimeSpan FlushInterval
    {
        get { return this.flushInterval; }
        set { this.flushInterval = value; }
    }

    protected override void SendBuffer(LoggingEvent[] events)
    {
        if (DateTime.Now - this.lastFlush > this.flushInterval)
        {
            base.SendBuffer(events);
            this.lastFlush = DateTime.Now;
        } 
    }
}

刷新间隔可以像其他附加器的常规设置一样进行配置:

The flush interval can be configured like normal settings of other appenders:

<flushInterval value="01:00:00" />

这篇关于防止log4net通过SMTP发送重复的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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