dotnet / dotnet/aspnetcore

Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware and CurrencyRate.WebApi.RequestHandle.ExceptionHandler in Azure Log stream

Open
#57,614 1 comment 0 reactions 0 assignees View on GitHub
area-mvc
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

I use approach with EcheptionHandler:
builder.Services.AddExceptionHandler();
app.UseExceptionHandler(_ => { });

And I have two logs from Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware and WebApi.RequestHandle.ExceptionHandler. I disable ExceptionHandlerMiddleware:
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware": "None"
}
}

builder.Logging.ClearProviders();

builder.Logging.AddAzureWebAppDiagnostics();
builder.Logging.AddFilter("Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware", LogLevel.None);

localy in Visual studio it work correct, but when I deploy in azure app service in Azure Log stream I see both logs.
How I can disable Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware for Azure Log stream

### Expected Behavior

I need one log from ExceptionHandler

### Steps To Reproduce

_No response_

### Exceptions (if any)

2024-08-30 14:35:54.741 +00:00 [Information] Microsoft.AspNetCore.Routing.EndpointMiddleware: Executed endpoint 'CurrencyRate.WebApi.Controllers.WeatherForecastController.Get (CurrencyRate.WebApi)'
2024-08-30 14:35:54.742 +00:00 [Error] Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware: An unhandled exception has occurred while executing the request.System.NullReferenceException: Object reference not set to an instance of an object.at CurrencyRate.WebApi.Controllers.WeatherForecastController.<>c.b__4_0(Int32 index) in D:\a\CurrencyRate\CurrencyRate\CurrencyRate.WebApi\Controllers\WeatherForecastController.cs:line 33at System.Linq.Enumerable.SelectRangeIterator`1.Fill(Span`1 results, Int32 start, Func`2 func)at System.Linq.Enumerable.SelectRangeIterator`1.ToArray()at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)at CurrencyRate.WebApi.Controllers.WeatherForecastController.Get() in D:\a\CurrencyRate\CurrencyRate\CurrencyRate.WebApi\Controllers\WeatherForecastController.cs:line 33at lambda_method3(Closure, Object, Object[])at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()--- End of stack trace from previous location ---at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()--- End of stack trace from previous location ---at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker)at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker)at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|7_0(Endpoint endpoint, Task requestTask, ILogger logger)at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.g__Awaited|10_0(ExceptionHandlerMiddlewareImpl middleware, HttpContext context, Task task)
2024-08-30 14:35:54.757 +00:00 [Error] CurrencyRate.WebApi.RequestHandle.ExceptionHandler: Exception occured : Object reference not set to an instance of an object.System.NullReferenceException: Object reference not set to an instance of an object.at CurrencyRate.WebApi.Controllers.WeatherForecastController.<>c.b__4_0(Int32 index) in D:\a\CurrencyRate\CurrencyRate\CurrencyRate.WebApi\Controllers\WeatherForecastController.cs:line 33at System.Linq.Enumerable.SelectRangeIterator`1.Fill(Span`1 results, Int32 start, Func`2 func)at System.Linq.Enumerable.SelectRangeIterator`1.ToArray()at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)at CurrencyRate.WebApi.Controllers.WeatherForecastController.Get() in D:\a\CurrencyRate\CurrencyRate\CurrencyRate.WebApi\Controllers\WeatherForecastController.cs:line 33at lambda_method3(Closure, Object, Object[])at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()--- End of stack trace from previous location ---at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()--- End of stack trace from previous location ---at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker)at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker)at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|7_0(Endpoint endpoint, Task requestTask, ILogger logger)at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.g__Awaited|10_0(ExceptionHandlerMiddlewareImpl middleware, HttpContext context, Task task)

### .NET Version

8.0

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.