ASP.Net Core-应用程序见解-堆栈跟踪

时间:2019-12-29 18:00:06

标签: asp.net-core azure-web-sites azure-application-insights azure-webapps

我正在设置一个非常简单的ASP.Net Core(2.2)MVC Web App。我希望能够看到任何应用程序错误(500秒钟)以及导致它们的原因,因此看起来Application Insights似乎是个好地方。

如果我进入Application Insights / Failures(“操作”选项卡-参见下面的屏幕截图),则可以查看所有500个错误的图形/计数。我可以单击“ DRILL INTO”按钮,查看详细信息(事件时间,请求名称等)的详细信息,但似乎无法获得有关错误/行号的实际原因的任何详细信息。

failures

基本上,我与此人有完全相同的问题: Azure Monitor / Application Insights not showing stack trace for errors (我的屏幕截图看起来一样)。

当我深入研究异常详细信息时,会得到如下信息:

myexception

要得到这样的东西:

Exception Section

我确实看到了有关通过Nuget将Application Insights添加到我的解决方案并将其放置的信息

 services.AddApplicationInsightsTelemetry();

进入Startup / ConfigureServices方法。

我还看到您可以查看Kudu日志等...,但我真的希望所有这些都可以在Application Insights中轻松访问。

有什么建议吗?

2 个答案:

答案 0 :(得分:0)

500 Internal server error(500内部服务器错误)表明您正在寻找堆栈跟踪信息,以找出问题所在和位置。您的示例中未提供任何代码,但您需要在代码周围加上try catch,然后记录异常以获取堆栈跟踪,或者可以按以下方式使用TelemetryClient:

var telemetry = new TelemetryClient();
...
try
{ ...
}
catch (Exception ex)
{
   // Set up some properties:
   var properties = new Dictionary <string, string>
     {{"Game", currentGame.Name}};

   var measurements = new Dictionary <string, double>
     {{"Users", currentGame.Users.Count}};

   // Send the exception telemetry:
   telemetry.TrackException(ex, properties, measurements);
}

更多信息,请访问Microsoft

答案 1 :(得分:0)

好的-我想我解决了自己的问题。事实证明,我不久前添加了Serilog(有点忘记了),并且在进入AI之前捕获了所有错误。当我从Program.cs和Startup.cs中删除Serilog配置代码时,应用程序异常开始显示在Application Insights / Failures中,同时显示了完整的调用堆栈。感谢您的建议!