将配置添加到Application Insights

时间:2017-05-03 23:34:43

标签: c# asp.net azure asp.net-core azure-application-insights

所以我最近通过Visual Studio将Application Insights安装到我的项目中,它说它是100%配置的,但我的Startup.cs中没有添加代码。我是否需要添加任何东西以使其完全正常运行,或者是它?

1 个答案:

答案 0 :(得分:1)

有两种方法可以将应用程序洞察添加到ASP.NET Core站点。

Program.cs文件中:

public static void Main(string[] args)
{
    var host = new WebHostBuilder()
        .UseKestrel()
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseIISIntegration()
        .UseStartup<Startup>()
        .UseApplicationInsights() // Here
        .Build();

    host.Run();
}

ConfigureServices方法:

public void ConfigureServices(IServiceCollection services)
{
    services.AddApplicationInsightsTelemetry(Configuration); // here
    var builder = services.AddMvc();
}

您需要在appsettings.json文件中添加检测密钥:

{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Information"
    }
  },
  "ApplicationInsights": {
    "InstrumentationKey": "4bbb7b98-78f8-49c3-8ede-da3215b75f43"
  }
}