简体   繁体   English

C# 如何调查:应用程序引发了未处理的异常

[英]C# How to investigate: An unhandled exception was thrown by the application

Hi I am getting the following error in my asp.net core logs:您好,我的 asp.net 核心日志中出现以下错误:

Microsoft.AspNetCore.Server.Kestrel|Connection id "XXXXX", Request id "YYYY:0000": An unhandled exception was thrown by the application.

Struggling to see how to investigate this further - how can I track down what is causing this?努力看看如何进一步调查这个问题 - 我怎样才能找到导致这个问题的原因? Is there any additional logging I can enable?我可以启用任何其他日志记录吗?

You will need to decorate your code with try/catch:你需要用 try/catch 来装饰你的代码:

try
{
    //code logic goes here
}
catch(Exception ex)
{
    //handle exception here
    //ex.Message - this will give you string description of the exception
    //ex.InnerException - this will provide you more details when you debug 
    //and have a break point in the exception section then you can view 
    //more details on the exception
}

I hope this helps.我希望这有帮助。

You can't catch this exception it is just logged.您无法捕获此异常,它只是被记录下来。 See for example source code .参见例如源代码 In vs you can set a functional breakpoint and load the symbols where needed.在vs中可以设置功能断点,在需要的地方加载符号。 Then you can set more breakpoints where needed.然后你可以在需要的地方设置更多的断点。

在此处输入图像描述

You can try using the ILogger from the Microsoft.Extensions.Logging , using the Method LogError.您可以尝试使用Microsoft.Extensions.Logging中的 ILogger,使用方法 LogError。

https://learn.microsoft.com/en-us/do.net/api/microsoft.extensions.logging.loggerextensions.logerror?view=do.net-plat-ext-7.0 https://learn.microsoft.com/en-us/do.net/api/microsoft.extensions.logging.loggerextensions.logerror?view=do.net-plat-ext-7.0

You will need to set the Log to output where you prefer, in the link bellow you can see the basic settings.您需要将日志设置为您喜欢的 output,在下面的链接中您可以看到基本设置。

https://learn.microsoft.com/en-us/as.net/core/fundamentals/logging/?view=as.netcore-7.0 https://learn.microsoft.com/en-us/as.net/core/fundamentals/logging/?view=as.netcore-7.0

In addition, if possible to debug, you can just enable more Exception setting while debugging.另外,如果可以调试的话,可以在调试的时候只开启更多的Exception设置。

At the bottom of the Visual Studio, this tab will appear, just enabled more options until a more specific exception appears.在 Visual Studio 的底部,将出现此选项卡,只是启用了更多选项,直到出现更具体的异常。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM