【问题标题】:Hook up application insights manually手动连接应用程序洞察力
【发布时间】:2018-03-08 14:25:59
【问题描述】:

我正在使用 VS for macOS 社区开发一个 asp.net 核心站点,不幸的是没有“添加应用程序洞察遥测”。

这使得https://docs.microsoft.com/en-us/azure/application-insights/app-insights-asp-net-core 有点不太有帮助......

那么,我该如何手动连接呢?

【问题讨论】:

    标签: macos azure azure-application-insights visual-studio-mac


    【解决方案1】:

    您可以手动进行更改。有 3 件事要做。

    1. 编辑您的 .csproj,通过添加此行来引入 ApplicationInsights。

    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.2.1" />

    1. 修改 Program.cs 以包含对 UseApplicationInsights() 的调用,如下所示。

      public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .UseApplicationInsights() .Build();

    2. 添加您的检测密钥 - 作为上述 UseApplicationInsights() 的参数或在 appsettings.json 中

      { "ApplicationInsights": { "InstrumentationKey": "11111111-2222-3333-4444-555555555555" } }

    现在运行应用程序,遥测数据将开始流向 Application Insights,

    wiki 中也描述了这些步骤: https://github.com/Microsoft/ApplicationInsights-aspnetcore/wiki/StartingDoc

    【讨论】:

    • 就这样?当我过去在常规项目中添加应用洞察时,我记得创建了一堆其他文件,并且在 VS 过程中有一堆步骤......比如 4-5 级安装或其他东西
    • VS 过程也很简单:它只是添加了 nuget 包并修改了一些配置文件,如果需要的话,还进行一些代码注入
    猜你喜欢
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 2016-09-17
    • 1970-01-01
    • 1970-01-01
    • 2015-11-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多