Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log unhandled exception in .net core

With ELMAH feature in web api 2.0 and Centralized logging and error handling , runtime calls logging module and decide if it can be handled then calls the handler else just logs it.. how can this feature be added in web api core. as we don't have inbuilt centralized unhandled logging feature..

One way I got is to use ExceptionHandler middleware and when it gets called, get the exception and log it or send email.. but what if handler doesn't get called .. how to log those unhandled exceptions ?

like image 288
zubin joshi Avatar asked Dec 06 '17 15:12

zubin joshi


1 Answers

Middleware could be a way to go yes. I've written a guide here: Error Logging Middleware in ASP.NET Core.

I would probably look at Microsoft.Extensions.Logging in combination with a logging framework like Serilog, NLog or log4net.

like image 160
ThomasArdal Avatar answered Oct 03 '22 12:10

ThomasArdal