'Prevent DefaultAntiforgery from logging errors

Is there a way to stop DefaultAntiforgery from logging errors? I see it takes an ILoggerFactory as parameter, which is a public type, but I don't know how to set it up since DefaultAntiforgery is internal.



Solution 1:[1]

I don't think this is a DI issue, but rather a configuration issue. What you want should be possible by configuring logging

Try something like this in your appsettings.json:

{
  "Logging": {
    // for all logging providers
    "LogLevel": {
      "Microsoft.AspNetCore.Antiforgery": "None"
    },
    // or just for the EventLog provider
    "EventLog": {
      "LogLevel": {
        "Microsoft.AspNetCore.Antiforgery": "None"
      }
    }
  }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tim