TL;DR: In my WebAPI
app, how can I use IExceptionHandler
and still prevent double logging issue?
What have I found searching:
ASP.NET Web API IExceptionLogger called twice
I have my own global error handler like this:
public class MyGlobalExceptionHandler: IExceptionHandler
which implements that one method it has: TryHandleAsync
The problem is it logs each error two times. One time using my own class and one time also Middleware
on its own decides to log an error without even going to my method, so I want to tell middleware not to log its own.
Here is my program.cs
: My feeling is that I should do more work regarding setting up that app.UseExceptionHandler
part so middleware doesn’t do its own thing. But I am not sure how it should be properly setup.
builder.Services.AddExceptionHandler<MyGlobalExceptionHandler>();
//
//
//
app.UseExceptionHandler(_ => { });
Like I said each error gets logged two times and even if I put breakpoints in my own class , it will only get hit one time which means even before getting there, Middleware has already decided to log it its own.