In ASP.NET Core applications, users disconnecting from a webpage while a request is still processing triggers an OperationCanceledException. This exception is logged as an error, creating noise that complicates system monitoring and alert management.
Initial attempts to filter these logs using NLog configuration failed because the logger lacks access to the HttpContext. Similarly, using middleware to catch exceptions proved ineffective, as logs are often generated by lower-level components like repositories before reaching the middleware.
The solution involves using the Scrutor library to decorate ILoggerProvider. By intercepting the logging process, the system can verify both the exception type and the state of HttpContext.RequestAborted to suppress unnecessary entries.
Decorating ILoggerProvider ensures comprehensive coverage, as it handles logs generated via ILoggerFactory, which are used by Kestrel, EF Core, and other internal libraries. This approach avoids the limitations of decorating ILogger directly.
The implementation requires registering IHttpContextAccessor and applying the decorator to ILoggerProvider. Developers should handle potential null references when logging occurs outside the HTTP pipeline and consider recursive checks for wrapped exceptions.






