NickCraver/StackExchange.Exceptional

Is there a way to filter logs by Client IP? Want to prevent logging at all from certain IP addresses

Closed this issue · 2 comments

Is there a way to filter logs by Client IP? Want to prevent logging at all from certain IP addresses.

Don't want to save logs from certain IP addresses in the database at all.

There's no way do to this via a built-in filter, because the concept is a lot more complicated than most devs imagine depending on context. "What is the user's IP?" gets really weird when behind a load balancer or DDoS protection layer (e.g. Fastly or CloudFlare) and...yeah. It's all weird.

But, you can likely do what you want in code in OnBeforeLog by setting Abort = true based on what you want. Here's an ASP.NET Core simple example that I hope helps!

services.AddExceptional(Configuration.GetSection("Exceptional"), settings =>
{
    settings.OnBeforeLog += (sender, args) =>
    {
        // Don't log local errors!
        if (args.Error.IPAddress == "127.0.0.1")
        {
            args.Abort = true;
        }
    };
});

Closing this out to cleanup - approach is above!