Is it possible to configure/extend log4net to stop loging the same exception during an extended outage?

134 Views Asked by At

We have a distributed micro service application using log4net with a custom appender in production. The problem is that during an outage on any external system or service, or even during a small hiccup in our Token provider service, for every user trying to hit that service we get one or several repeated logs, multiply that for all users and we get over 20000 repeated logs in 15 minutes overflowing our quota.

We want to stop spamming our log with this without adding catching to the c# micro services if possible.

I tried filtering specific logs but log4net's filtering only works positively, like so:

I want to filter logs with the word "Token" in them:

    <filter type="log4net.Filter.StringMatchFilter">
        <acceptOnMatch value="false" />
        <stringToMatch value="Token" />
    </filter>

But..errors messages with "Token" are still logged :(

Peculiarly, with the following filter:

    <filter type="log4net.Filter.StringMatchFilter">
        <acceptOnMatch value="**true**" />
        <stringToMatch value="Token" />
    </filter>
    <filter type="log4net.Filter.DenyAllFilter" />

Only messages that contain the string "Token" are logged (OK, it's the behavior that I would hope)

And with the following filter:

    <filter type="log4net.Filter.StringMatchFilter">
        <acceptOnMatch value="false" />
        <stringToMatch value="Token" />
    </filter>
    <filter type="log4net.Filter.DenyAllFilter" />

No message is recorded in log (OK, it's the behavior that I would hope)

The entry in Apaches documentation for AcceptOnMatch:

"The AcceptOnMatch property is a flag that determines the behavior when a matching Level is found. If the flag is set to true then the filter will Accept the logging event, otherwise it will Neutral the event."

So how is it Denied? Is this behavior even possible? any ideas?

Sorry for the length of this post, any possible solution to my original problem is most welcome, be it for this filtering problem or an alternative to avoid spamming the logs.

Thanks a lot for reading!

0

There are 0 best solutions below