c# - ApplicationInsights,ApplicationInsightsTelemetryWorkerService,在配置中设置 EnableAdaptiveSampling
问题描述
在“worker”应用程序(.net core 3.1)中,我通过以下方式配置了 ApplicationInsightsTelemetryWorkerService:
services.AddApplicationInsightsTelemetryWorkerService(options =>
{
options.DeveloperMode = false;
options.EnableAdaptiveSampling = false;
});
在 appsettings.json 中 InstrumentationKey 定义为:
"ApplicationInsights": {
"InstrumentationKey": "xxxx-xxxx-xxxx-xxxx-xxxx"
},
我想将“EnableAdaptiveSampling”设置从代码移动到 json 文件。当我尝试将它添加到“EnableAdaptiveSampling”之类的 ApplicationInsights 部分时:false,它似乎没有捡起它。
在配置文件中设置它的正确方法是什么
解决方案
您必须通过代码读取配置并进行设置。在 .net 核心中,没有像 InstrumentationKey 这样的自适应采样的预定义设置的自动拾取。例如:
appsettings.json:
"ApplicationInsights": {
"InstrumentationKey": "xxxx-xxxx-xxxx-xxxx-xxxx",
"EnableAdaptiveSampling": "false"
},
代码:
// instrumentation key is read automatically from appsettings.json
services.AddApplicationInsightsTelemetryWorkerService(options =>
{
options.DeveloperMode = false;
options.EnableAdaptiveSampling = hostContext.Configuration.GetValue<bool>("ApplicationInsights:EnableAdaptiveSampling");
});
推荐阅读
- quarkus - How can I include an additional resource in a native image built with Quarkus?
- terraform - 就地交换负载均衡器侦听器
- verilog - Verilog 在启动期间总是阻塞执行
- r - 如何格式化我的数据集(来自 Grahpad Prism)以与 R 一起使用(每个样本一行)?
- spring-boot - @LoadBalanced WebClient 不适用于 @RestClientTest 单元测试
- vim - 如何摆脱 vim quickfix 列表中的行号?
- laravel - 有没有办法将参数发送给观察者?
- git - Visual Studio 2019 Github 扩展命令:“pop and restore staged”与“pop all as unstaged”?
- sql - JSON to SQL variable string
- php - 如何使用 PHP 抓取网站的特定元素?