[英]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.使用 web api 2.0 中的 ELMAH 功能和集中式日志记录和错误处理,运行时调用日志记录模块并决定是否可以处理它,然后调用处理程序,否则只记录它。如何在 web api 核心中添加此功能。 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 ?我得到的一种方法是使用 ExceptionHandler 中间件,当它被调用时,获取异常并记录它或发送电子邮件..但是如果没有调用处理程序怎么办..如何记录那些未处理的异常?
Middleware could be a way to go yes.中间件可能是一种方式,是的。 I've written a guide here: Error Logging Middleware in ASP.NET Core .我在这里写了一个指南: 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.我可能会结合像 Serilog、NLog 或 log4net 这样的日志框架来查看Microsoft.Extensions.Logging 。
If you're already using Application Insights, you can set up alerts in the portal.如果您已经在使用 Application Insights,则可以在门户中设置警报。 https://docs.microsoft.com/en-us/azure/azure-monitor/learn/tutorial-alert https://docs.microsoft.com/en-us/azure/azure-monitor/learn/tutorial-alert
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.