dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.52k stars 10.04k forks source link

Add `ExceptionHandlerOptions.SuppressLoggingOnHandledException` #59075

Open JamesNK opened 2 hours ago

JamesNK commented 2 hours ago

Background and Motivation

A config option to only log in exception handler middleware if the exception is unhandled.

For https://github.com/dotnet/aspnetcore/issues/54554

Proposed API

namespace Microsoft.AspNetCore.Builder;

public class ExceptionHandlerOptions
{
+    public bool SuppressLoggingOnHandledException { get; set; }
}

Defaults to false.

Usage Examples

app.UseExceptionHandler(new ExceptionHandlerOptions()
{
    SuppressLoggingOnHandledException = true
});

Alternative Designs

Could make the new behavior the default. I don't think that is a good idea for backwards compatibility reasons, and some people might prefer the current behavior.

Risks

dotnet-policy-service[bot] commented 2 hours ago

Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that: