无法将ASP.NET核心web应用程序与Application Insights连接

无法将ASP.NET核心web应用程序与Application Insights连接,asp.net,asp.net-mvc,azure,asp.net-core,azure-application-insights,Asp.net,Asp.net Mvc,Azure,Asp.net Core,Azure Application Insights,我有一个ASP.NET核心MVC项目,它是这些新型产品中的一个,在Azure应用程序服务上托管的Visual Studio Community 2015 Update 3中作为控制台应用程序启动。我正在尝试设置应用程序洞察,主要是因为我想用ApplicationInsightStracListener捕获诊断跟踪,但其他功能也很有用。我还没有找到正确的配置来让任何东西显示在Azure门户中 我使用visualstudio扩展向我的项目添加了applicationinsights支持。然而,这似乎

我有一个ASP.NET核心MVC项目,它是这些新型产品中的一个,在Azure应用程序服务上托管的Visual Studio Community 2015 Update 3中作为控制台应用程序启动。我正在尝试设置应用程序洞察,主要是因为我想用ApplicationInsightStracListener捕获诊断跟踪,但其他功能也很有用。我还没有找到正确的配置来让任何东西显示在Azure门户中

我使用visualstudio扩展向我的项目添加了applicationinsights支持。然而,这似乎是开始出错的地方,它没有创建ApplicationInsights.config。它添加了一些DLL,并将InstrumentationKey放入我的应用程序设置文件中,我还通过NuGet手动添加了一些程序集,包括Microsoft.ApplicationInsights.Web和Microsoft.ApplicationInsights.TraceListener。此时发布将导致Azure门户中没有启用任何指标,并且实时流告诉我不可用:您的应用程序处于脱机状态或使用较旧的SDK

我试过2.1.0和2.2.0测试版。我尝试过删除所有的ApplicationInsights内容,重新安装扩展,然后重新开始。我还尝试跳过使用扩展名,手动添加Microsoft.ApplicationInsights.Web等,一些谷歌结果暗示应该也创建配置文件,但没有成功。我从网上下载了其他人的ApplicationInsights.config文件,并试图使它们适合我的环境。在门户的Application Insights部分,从来没有任何东西起过作用

除了创建配置文件外,扩展还应该采取哪些额外步骤?我需要向Startup.cs添加代码吗?大多数文档似乎都认为初始设置可以正常工作。

考虑到您的InstrumentationKey位于appsettings.json上,您需要修改Startup.cs:

      "ApplicationInsights": {
    "InstrumentationKey": "xxxxxxx-xxxxx-xxxx-xxx-xxxxxxxxxx"
  }
重要的是app.UseApplicationInsightsRequestTelemetry在app.UseMvc之前。

考虑到您的InstrumentationKey位于appsettings.json上,您需要修改Startup.cs:

      "ApplicationInsights": {
    "InstrumentationKey": "xxxxxxx-xxxxx-xxxx-xxx-xxxxxxxxxx"
  }

重要的是,app.UseApplicationInsightsRequestTelemetry在app.UseMvc之前。

ASP.NET核心项目有一个单独的AI SDK,您可以找到ApplicationInsights aspnetcore和Microsoft.ApplicationInsights.aspnetcore

要开始收集,在添加适当的Nuget包(即请求和异常收集中间件)后,AI中间件应连接到项目代码中。启动时应添加构建AI配置的附加步骤

在GitHub项目中,应该包括这一点,但我今天发现它是空的,然而,经验提到如何添加InstrumentationKey和一些额外的集合,例如,对于基于配置的方法来设置IKey:

如果您使用的是json配置提供程序-请将以下内容添加到config.json中

    "ApplicationInsights": {
    "InstrumentationKey": "11111111-2222-3333-4444-555555555555"
}
如果您使用的是环境变量:

SET ApplicationInsights:InstrumentationKey=11111111-2222-3333-4444-555555555555
注意:不支持azure网站APPINSIGHTS\u INSTRUMENTATIONKEY设置的环境变量

或在应用程序配置设置名称中定义的任何其他配置提供程序格式为ApplicationInsights:InstrumentationKey,然后在Startup.cs中调用AddInsights telemetry:

services.AddApplicationInsightsTelemetry(Configuration);

ASP.NET核心项目有一个单独的AI SDK,您可以找到ApplicationInsights aspnetcore和Microsoft.ApplicationInsights.aspnetcore

要开始收集,在添加适当的Nuget包(即请求和异常收集中间件)后,AI中间件应连接到项目代码中。启动时应添加构建AI配置的附加步骤

在GitHub项目中,应该包括这一点,但我今天发现它是空的,然而,经验提到如何添加InstrumentationKey和一些额外的集合,例如,对于基于配置的方法来设置IKey:

如果您使用的是json配置提供程序-请将以下内容添加到config.json中

    "ApplicationInsights": {
    "InstrumentationKey": "11111111-2222-3333-4444-555555555555"
}
如果您使用的是环境变量:

SET ApplicationInsights:InstrumentationKey=11111111-2222-3333-4444-555555555555
注意:不支持azure网站APPINSIGHTS\u INSTRUMENTATIONKEY设置的环境变量

或在应用程序配置设置名称中定义的任何其他配置提供程序格式为ApplicationInsights:InstrumentationKey,然后在Startup.cs中调用AddInsights telemetry:

services.AddApplicationInsightsTelemetry(Configuration);

UseApplicationInsightsCeptionTeletry应在使用MVC之前进行。如果我在使用MVC之后使用它,它不会保存异常,我只看到请求。当然,您还应该添加nuget软件包Microsoft.ApplicationInsights.AspNetCore并添加到appsettings.json:

      "ApplicationInsights": {
    "InstrumentationKey": "xxxxxxx-xxxxx-xxxx-xxx-xxxxxxxxxx"
  }
我的Startup.cs看起来:

    public Startup(IHostingEnvironment env)
    {
        ...
        if (env.IsDevelopment())
        {
            builder.AddApplicationInsightsSettings(developerMode: true);
        }
    }

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

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        app.UseApplicationInsightsRequestTelemetry();
        app.UseApplicationInsightsExceptionTelemetry();

        app.UseMvc();
    }

UseApplicationInsightsCeptionTeletry应在使用MVC之前进行。如果我在使用MVC之后使用它,它不会保存异常,我只看到请求。当然,您还应该添加nuget软件包Microsoft.Applicationo ninights.AspNetCore并添加到appsettings.json:

      "ApplicationInsights": {
    "InstrumentationKey": "xxxxxxx-xxxxx-xxxx-xxx-xxxxxxxxxx"
  }
我的Startup.cs看起来:

    public Startup(IHostingEnvironment env)
    {
        ...
        if (env.IsDevelopment())
        {
            builder.AddApplicationInsightsSettings(developerMode: true);
        }
    }

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

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        app.UseApplicationInsightsRequestTelemetry();
        app.UseApplicationInsightsExceptionTelemetry();

        app.UseMvc();
    }

谢谢,很高兴知道为什么扩展不工作。谢谢,很高兴知道为什么扩展不工作。