ASP.NET Core MVC应用程序洞察在升级到.NET Core 1.1.1后停止工作

Paw*_*oka 8 .net c# asp.net-core-mvc azure-application-insights asp.net-core

我有一个简单的ASP.NET核心应用程序,我在2016年12月工作.它在应用程序见解和遥测方面工作得很好.

现在4个月后,我想开始从.NET Core 1.1.0升级到1.1.1.在此过程中,包Microsoft.ApplicationInsights.AspNetCore已从版本更新1.0.2到版本2.0.0.

这不幸导致我的应用程序停止工作,特别是我收到此错误:

An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately.

/Views/Shared/_Layout.cshtml

'IHtmlHelper<dynamic>' does not contain a definition for 'ApplicationInsightsJavaScript' and no extension method 'ApplicationInsightsJavaScript' accepting a first argument of type 'IHtmlHelper<dynamic>' could be found (are you missing a using directive or an assembly reference?)
+
    @Html.ApplicationInsightsJavaScript(TelemetryConfiguration)

Show compilation source
#pragma checksum "/Views/Shared/_Layout.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "050a2afdfb4a44e17be72e76627a3d3a0d0b7d5a"
namespace AspNetCore
{
#line 1 "/Views/_ViewImports.cshtml"
Run Code Online (Sandbox Code Playgroud)

屏幕:

在此输入图像描述

从project.json升级到新的csproj并使用新的Visual Studio 2017没有帮助.

看起来ApplicationInsightsJavaScript基本上已从API中删除.如何启用javascript应用程序洞察呢?

Tse*_*eng 23

从ApplicationInsights 1.x到2.x有重大更改,这些更改记录在GitHub 发行说明中.

  • 此版本包含SDK内部的重写,以便更好地进行.N​​ET Core集成和初始化.
  • UseApplicationInsightsRequestTelemetry 它已经过时了,它现在自动处理它所用的逻辑,应该从Startup.cs中删除对这个方法的调用.
  • UseApplicationInsightsExceptionTelemetry已过时,异常遥测现在在内部自动处理.您应该从Startup.cs中删除对此方法的调用,否则您将收到重复的异常遥测报告.
  • 已删除JavaScript代码段的MVC依赖项,因此为了包含JavaScript代码段,您需要进行以下更改:
    • 在_ViewImports.cshtml中替换@inject Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration TelemetryConfiguration@inject Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet JavaScriptSnippet
    • 在_Layout.cshtml中替换 @Html.ApplicationInsightsJavaScript(TelemetryConfiguration)@Html.Raw(JavaScriptSnippet.FullScript)