|
| 1 | +--- |
| 2 | +title: "Breaking change: Exception diagnostics are suppressed when IExceptionHandler.TryHandleAsync returns true" |
| 3 | +description: Learn about the breaking change in ASP.NET Core 10 where exception diagnostics are no longer recorded when IExceptionHandler.TryHandleAsync returns true. |
| 4 | +ms.date: 08/08/2025 |
| 5 | +--- |
| 6 | + |
| 7 | +# Exception diagnostics are suppressed when IExceptionHandler.TryHandleAsync returns true |
| 8 | + |
| 9 | +The ASP.NET Core exception handler middleware no longer records diagnostics for exceptions handled by <xref:Microsoft.AspNetCore.Diagnostics.IExceptionHandler> by default. |
| 10 | + |
| 11 | +## Version introduced |
| 12 | + |
| 13 | +.NET 10 Preview 7 |
| 14 | + |
| 15 | +## Previous behavior |
| 16 | + |
| 17 | +Previously, the exception handler middleware recorded diagnostics about exceptions handled by <xref:Microsoft.AspNetCore.Diagnostics.IExceptionHandler>. |
| 18 | + |
| 19 | +The exception diagnostics are: |
| 20 | + |
| 21 | +- Logging `UnhandledException` to <xref:Microsoft.Extensions.Logging.ILogger>. |
| 22 | +- Writing the `Microsoft.AspNetCore.Diagnostics.HandledException` event to <xref:Microsoft.Extensions.Logging.EventSource>. |
| 23 | +- Adding the `error.type` tag to the `http.server.request.duration` metric. |
| 24 | + |
| 25 | +## New behavior |
| 26 | + |
| 27 | +Starting in .NET 10, if <xref:Microsoft.AspNetCore.Diagnostics.IExceptionHandler.TryHandleAsync%2A?displayProperty=nameWithType> returns `true`, then exception diagnostics are no longer recorded by default. |
| 28 | + |
| 29 | +## Type of breaking change |
| 30 | + |
| 31 | +This change is a [behavioral change](../../categories.md#behavioral-change). |
| 32 | + |
| 33 | +## Reason for change |
| 34 | + |
| 35 | +ASP.NET Core users have given feedback that the previous behavior was undesirable. Their <xref:Microsoft.AspNetCore.Diagnostics.IExceptionHandler> implementation reported that the exception was handled, but the error handling middleware still recorded the error in the app's telemetry. |
| 36 | + |
| 37 | +ASP.NET Core now follows the behavior expected by users by suppressing diagnostics when <xref:Microsoft.AspNetCore.Diagnostics.IExceptionHandler> handles the exception. Configuration options are also available to customize exception diagnostics behavior if needed. |
| 38 | + |
| 39 | +## Recommended action |
| 40 | + |
| 41 | +If you want handled exceptions to continue to record telemetry, you can use the new `ExceptionHandlerOptions.SuppressDiagnosticsCallback` option: |
| 42 | + |
| 43 | +```csharp |
| 44 | +app.UseExceptionHandler(new ExceptionHandlerOptions |
| 45 | +{ |
| 46 | + SuppressDiagnosticsCallback = context => false; |
| 47 | +}); |
| 48 | +``` |
| 49 | + |
| 50 | +The `context` passed to the callback includes information about the exception, the request, and whether the exception was handled. The callback returns `false` to indicate that diagnostics shouldn't be suppressed, thus restoring the previous behavior. |
| 51 | + |
| 52 | +## Affected APIs |
| 53 | + |
| 54 | +- <xref:Microsoft.AspNetCore.Builder.ExceptionHandlerExtensions.UseExceptionHandler%2A?displayProperty=fullName> |
| 55 | +- <xref:Microsoft.AspNetCore.Diagnostics.IExceptionHandler?displayProperty=fullName> |
0 commit comments