Closed siimonemoretti closed 2 days ago
Isn't this issue already known when implementing IExceptionHandler and the workaround is setting the logging to None for ExceptionHandlingMiddleware
"Logging": { "LogLevel": { "Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware": "None" }
Yes, I forgot to show that I enabled that setting too.
I've experienced the same behaviour and I don't know how to solve it. Using the .NET 7 middlware strategy the logger works properly but applying the new .NET 8 Global Exception Handler Serilog is not the only logger that intercepts the exception. Other logs excluding the exception handling ( normal application behaviour ) are ok but when the code generates an exception it is logged twice.
LoggerTest.zip Here I've created a demo solution that shows the problem. Invoking the WebAPI you'll see that the console shows the logging messages only once. When exception is thrown it is intercepted by the Global Exception Handler and logs the issue, but before that, another handler has still logged the same exception, generating a copy of the error message.
This looks like a duplicate of #341
UseSerilogRequestLogging()
has logged exceptions for a long time; adding a new exception handling mechanism (IExceptionHandler
) hasn't changed that, the example given above is logging the exceptions twice because both the Serilog handler (vial UseSerilogRequestLogging()
) and the registered global one are being hit.
Having a means to turn off exception logging in UseSerilogRequestLogging()
would be the way to go. .NET 8 Global Exception Handler logs twice. https://github.com/serilog/serilog-aspnetcore/issues/341 is tracking this so let's move the discussion and focus over there, so we can edge towards a configuration setting for it.
Description As title suggests, using Global Exception handler logs twice on exceptions but not on simple logs. This happens both on console and file sink, so I don't think the issue is with the sink but rather on the Global Exception Handler.
Demo:
Here, logs are logged fine.
Reproduction
The appsettings.json:
The program.cs:
The GlobalExceptoinHandler.cs:
Expected behavior Expected to see only one log event when an exception is thrown.
Relevant package, tooling and runtime versions![immagine](https://github.com/serilog/serilog-aspnetcore/assets/118049024/91be5223-23f4-48aa-a530-9c5acdf5d1bf)