views:

95

answers:

1

Hi,

we have bridged our log4net with Jira using SMTP.

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.

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.

+3  A: 

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" />
Stefan Egli