gpt4 book ai didi

c# - 如何追踪 AppInsights 内部错误

转载 作者:行者123 更新时间:2023-12-03 04:41:02 25 4
gpt4 key购买 nike

我的系统的一些常规设置:

  • Windows x64
  • .net 3.1
  • AspNet.Core
  • Serilog + AppInsights 编写器

最近,我们开始观察许多如下所示的跟踪日志。我认为当我们尝试将日志写入 AppInsights 时出现了问题。但我们可以看到我们的日志。看来我们已经拥有了正确登录 AppInsights 所需的一切。但我们也记录了这种不需要的跟踪消息,而且数量很多。

此跟踪消息发生在我的本地计算机上的 Azure AKS 环境中。但堆栈跟踪太短,无法帮助定位错误的根源。

AI (Internal): [Microsoft-ApplicationInsights-Core] [msg=Log Error];[msg=Exception while initializing Microsoft.ApplicationInsights.AspNetCore.TelemetryInitializers.ClientIpHeaderTelemetryInitializer, exception message - System.ObjectDisposedException: Request has finished and HttpContext disposed.
Object name: 'HttpContext'.
at Microsoft.AspNetCore.Http.DefaultHttpContext.ThrowContextDisposed()
at Microsoft.AspNetCore.Http.DefaultHttpContext.get_Features()
at Microsoft.ApplicationInsights.AspNetCore.TelemetryInitializers.TelemetryInitializerBase.Initialize(ITelemetry telemetry)
at Microsoft.ApplicationInsights.TelemetryClient.Initialize(ITelemetry telemetry)]

最佳答案

我尝试创建一个环境,使用 Asp.net core 应用程序和 .net3.1 来跟踪日志(请求、异常、用户、失败、跟踪等)

以下是我遵循的步骤:将应用程序洞察遥测添加到我的应用程序并安装 NuGet 包 Microsoft.ApplicationInsights.AspNetcore

enter image description here

并在 startup.csservices.AddControllersWithViews(); 添加

services.AddApplicationInsightsTelemetry(Configuration["APPINSIGHTS_CONNECTIONSTRING"]);

enter image description here

将应用程序部署到azure后,为了跟踪日志,请转到我创建的应用程序洞察>事务搜索>查看数据,我们可以在其中看到如下所有日志,也可以确定是否发生任何错误。

enter image description here

我们还可以使用 kudu-console 下载所有日志并追踪应用程序。前往应用服务>高级工具>前往

enter image description here

enter image description here

欲了解更多信息,请参阅以下链接:

MS DOC | Explore .NET/.NET Core and Python trace logs in Application Insights

SO Thread | Application Insights not showing stack trace for errors

Blog| Using Azure Application Insights For Exception Logging In C#

关于c# - 如何追踪 AppInsights 内部错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69459232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com