【发布时间】:2017-11-01 04:46:19
【问题描述】:
我正在尝试在 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。
我在 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 变量未设置(这意味着它默认为生产)。为了确保,我将环境值输出到视图以确保它确实呈现“生产”
我做错了什么?
我尝试关注这个帖子:Asp.Net Core and Application Insight in VS2017 - multiple environments,但我听不懂。
呵呵
【问题讨论】:
-
查看此示例以将 SF 配置用于 AI 密钥:github.com/Azure-Samples/service-fabric-dotnet-getting-started/…
-
@MikkelMørkHegnhøj,谢谢。通过使用这种方法,我应该从我的 ASP.NET Web SF 服务的 Startup.cs 中删除 ApplicationInsight 设置吗?
-
不 - 这只是你如何从配置中获取密钥到你的代码。
-
嗯,好的。我按照您提供的链接中的说明进行操作,但我还从 Startup.cs 和 appsetting.json 文件中删除了所有旧 AI 设置,一切正常。我的 asp.net 无状态服务的构造函数中提供的代码似乎就足够了。
-
很高兴你让它工作:-)
标签: asp.net asp.net-mvc azure-service-fabric appsettings