什么是遥测配置以及为什么我们在asp.net核心中使用它?

时间:2016-09-25 19:23:38

标签: asp.net-core asp.net-core-mvc azure-application-insights

我是ASP.NET Core 1的新手。我在_Layout.cshtml中看到了这样的代码部分。

@Html.ApplicationInsightsJavaScript(TelemetryConfiguration)

我无法理解它是什么。

1 个答案:

答案 0 :(得分:2)

在应用程序中添加TelemetryConfiguration后,您可以从应用程序的服务器(后端)发送遥测数据。使用此功能,您可以添加客户端监控。这将为您提供有关用户,会话,页面查看以及浏览器中发生的任何异常或崩溃的数据。

要启用Application Insights,您需要将“Microsoft.ApplicationInsights.AspNetCore”添加到project.json文件

"Microsoft.ApplicationInsights.AspNetCore": "1.0.0-rc2-final"

在方法ConfigureServices中添加像这样的Application Insights服务 -

public void ConfigureServices(IServiceCollection services)
{
    services.AddApplicationInsightsTelemetry(Configuration);
    services.AddMvc();
}

在_ViewImports.cshtml中,像这样添加注入 -

@inject Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration TelemetryConfiguration 

您希望从该页面报告的任何自定义javascript遥测都应在此片段后注入。

@Html.ApplicationInsightsJavaScript(TelemetryConfiguration)

post

中说明的详细信息