c# - ASP.NET Core 2.1 Web.API 更改应用程序洞察力记录的检测密钥
问题描述
我想启用从 WebApi (使用自定义记录器)记录到应用程序洞察力。一切正常,但我需要提供instrumentation key
强制appsetting.json
约定:
"Values": {
"AppInsightsKey": "I want to put key here"
},
"ApplicationInsights": {
"InstrumentationKey": "Now I must put key here"
}
有什么办法可以正确设置吗?
实际上在我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。如果我可以ApplicationInsights.InstrumentationKey
在 Azure 上覆盖,这也是正确的解决方案。
解决方案
将检测密钥设置为环境变量“APPINSIGHTS_INSTRUMENTATIONKEY”。它应该由 Application Insights SDK 获取。
推荐阅读
- r - Is there a way to make R code only able to be run and not edited? Essentially read-only?
- python - 为什么 Python docx 或 lxml 将属性从一个节点移动到另一个节点?
- javascript - 标题过滤和选择带有复选框列的行返回所有行
- sql - 在(Hive)的情况下使用查询表的一列的总和
- excel - Excel VLOOKUP 打破了一定的价值
- wpf - Button Border clipped in WPF with 125% DPI Setting
- excel - Excel if statement produces `#NUM` unexpectedly
- r - Upload Powerpoint to Google Drive as file
- java - selenium 中的测试脚本以验证网页标题
- python - 如何在 Pytorch 模型中添加验证和测试集?