簡體   English   中英

Application Insights ASP.NET核心環境appsettings.json

[英]Application Insights ASP.NET Core Environment appsettings.json

我正在嘗試在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"
}

但是由於某種原因,當我將應用程序發布到生產環境時,該應用程序會不斷發布到開發應用程序洞察密鑰xxxx-xxx-xxx……似乎未使用生產應用程序洞察密鑰。

我在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變量(這意味着它默認為生產)。 為了確保這一點,我將環境值輸出到View中以確保它確實呈現“生產”

我究竟做錯了什么?

我試圖遵循這篇文章: VS2017中的Asp.Net Core和Application Insight-多個環境,但我聽不懂。

Hooroo

請參閱https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/configuration/?view=aspnetcore-2.1#providers 根據本文, appsettings.json取代了特定於環境的appsettings.<environment>.json文件。 因此,根據您的情況,只需將默認的 appsettings.json重命名為appsettings.development.json

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM