应用程序洞察ASP.NET核心环境appsettings.json

时间:2017-05-31 11:38:23

标签: asp.net asp.net-mvc azure-service-fabric appsettings

我正在尝试在Service Fabric中运行的ASP.NET应用程序中配置Application Insights。

在appsettings.json中设置以下内容时,它在我的开发框中运行良好:

"ApplicationInsights": {
    "InstrumentationKey": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}

我还有一个appsettings.Production.json文件,其中包含以下设置:

"ApplicationInsights": {
    "InstrumentationKey": "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy"
}

但出于某种原因,当我将应用程序发布到生产环境时,应用程序会一直发布到Dev Application Insights Key xxxx-xxx-xxx ......似乎没有使用Production Application Insights Key。 / p>

我在Startup.cs中有以下设置:

var builder = new ConfigurationBuilder()
            .SetBasePath(env.ContentRootPath)
            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
            .AddEnvironmentVariables();

此外,我的节点上的ASPNETCORE_ENVIRONMENT变量未设置(这意味着它默认为Production)。为了确保,我将环境值输出到View以确保它确实呈现“生产”

我做错了什么?

我试着关注这篇文章:Asp.Net Core and Application Insight in VS2017 - multiple environments但我无法理解。

Hooroo

1 个答案:

答案 0 :(得分:0)

请参阅https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-2.1#providers。根据本文,appsettings.json取代了特定于环境的appsettings.<environment>.json文件。因此,根据您的情况,只需将您的默认 appsettings.json重命名为appsettings.development.json

相关问题