C
C#2d ago
KARTOOS

Logging unhandled/fatal exception in .net core 8

I want to log fatal/unhandled exceptions to the db . I used to work on .net framework and over there I used a combination of global.asax.cs (application_error) and log4net to achieve this. Can someone kindly tell me hownit can be achieved in .net core 8 for a project that is a rest API. I was looking into global error handling using UseExceptionHandler. But since I am new to .net core in general was feeling a bit confused. Thanks in advance.
9 Replies
Angius
Angius2d ago
Exception handling middleware would be one way
KARTOOS
KARTOOSOP2d ago
I would have to dig into what are middlewares. But I assume it is related to the UseExceptionHandler?
Angius
Angius2d ago
https://dev.to/andytechdev/aspnet-core-middleware-working-with-global-exception-handling-3hi0 here's a decent article on the topic This one just uses regular middleware pipeline .UseExceptionHandler() also uses a middleware, IIRC It basically captures the erorr, and redirects to some other route where you can handle it Haven't used it with APIs, though, so can't say for sure
KARTOOS
KARTOOSOP2d ago
Thanks , I will look into the resource you shared.
Muhammad Ali
Muhammad Ali2d ago
Go for global exception handling.
Sehra
Sehra2d ago
Handle errors in ASP.NET Core
Discover how to handle errors in ASP.NET Core apps.
KARTOOS
KARTOOSOP2d ago
Can you please share a link or is it the same as the one above?
Muhammad Ali
Muhammad Ali2d ago
Sorry, I didn't read the replies. yes it is same.
KARTOOS
KARTOOSOP2d ago
Thanks a lot all, you guys are awesome

Did you find this page helpful?