繁体   English   中英

ASP.NET Core 2.1 Web.API更改应用程序见解的日志记录检测键

[英]ASP.NET Core 2.1 Web.API change application insights instrumentation key for logging

我想启用从WebApi(使用自定义记录器)到应用程序见解的日志记录。 一切正常,但是我需要在appsetting.json提供带有强制约定的instrumentation key

"Values": {
   "AppInsightsKey":  "I want to put key here" 
},
"ApplicationInsights": {
   "InstrumentationKey": "Now I must put key here"
}

但是,我不能直接从Azure设置覆盖此第二个设置: 在此处输入图片说明

有什么办法可以正确设置它?

实际上,在我的Startup.cs我正在配置记录器:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace);
}

我的记录器包装器:

using Microsoft.Extensions.Logging;
...
public class MyCustomLogger : IMyCustomLogger
{
    private readonly ILogger _logger;

    public MyCustomLogger(ILogger<MyCustomLogger> logger)
    {
        _logger = logger;
    }
    public void LogInformation(string message, params object[] args)
    {
        _logger.LogInformation(message, args);
    }
}

PS。 如果我可以在Azure上重写ApplicationInsights.InstrumentationKey ,那么这也是正确的解决方案。

但是,我不能直接从Azure设置覆盖此第二个设置:

请添加具有以下格式ApplicationInsights:InstrumentationKey的应用程序作为Azure应用程序设置中的appsetting密钥。 有关更多信息,请参阅本教程

在此处输入图片说明

将检测键设置为环境变量“ APPINSIGHTS_INSTRUMENTATIONKEY”。 它应该由Application Insights SDK提取。

在将Insights添加到WebHostBuilder的Program.cs中,可以执行.UseApplicationInsights("YourKeyHere")而不是.UseApplicationInsights() .UseApplicationInsights("YourKeyHere")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM