【发布时间】:2018-12-14 19:46:38
【问题描述】:
我想启用从 WebApi(使用自定义记录器)记录到应用洞察的功能。
一切正常,但我需要在appsetting.json 中提供instrumentation key 强制约定:
"Values": {
"AppInsightsKey": "I want to put key here"
},
"ApplicationInsights": {
"InstrumentationKey": "Now I must put key here"
}
有什么方法可以正确设置吗?
其实在我的Startup.cs我正在配置logger:
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);
}
}
附言。如果我可以在 Azure 上覆盖 ApplicationInsights.InstrumentationKey,这也是正确的解决方案。
【问题讨论】:
标签: c# azure asp.net-core-webapi azure-application-insights asp.net-core-2.1