简体   繁体   English

如何在 .net core 中记录未处理的异常

[英]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

Try this port of Elmah to .NET Core.尝试将此Elmah移植到 .NET Core。

services.AddElmah(); // in ConfigureServices 

app.UseElmah(); // in Configure, before UseMvc()

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.

相关问题 如何在 ASP.NET MVC 中使用 NLog 记录未处理的异常 - How log an unhandled exception with NLog in ASP.NET MVC 如何在Silverlight 5中记录未处理的异常 - how to log Unhandled Exception in Silverlight 5 如何在 dot net core 中设置 log4net 以记录所有未处理的异常? - How can I set up log4net in dot net core to log all unhandled exceptions? ASP .NET Core 3.1 中的“未处理”异常 - “Unhandled” exception in ASP .NET Core 3.1 有未处理的异常时如何确保记录异常 - How to ensure log the exception when there is unhandled exception 记录未处理的异常 - Log unhandled exception 更新asp.net core 5中的文本字段时如何解决“未处理的异常”问题? - How to solve "unhandled exception" issue while updating text field in asp.net core 5? 处理请求时发生未处理的异常 - ASP .NET Core - An unhandled exception occurred while processing the request- ASP .NET Core .Net核心身份2提供程序登录取消导致未处理的异常 - .Net Core Identity 2 Provider login Cancel leads to unhandled exception ASP.NET Core 2.2创建表单时出现未处理的异常 - ASP.NET core 2.2 Unhandled exception when creating a form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM