c# - Application Insights 具有指标和依赖项,但没有信息跟踪
问题描述
我有一个 ASP net 5。我看不到我的自定义 Traces,但我可以看到 Metrics and Dependencies 我认为这是 LogLevel 的问题,但似乎我找不到正确的设置:
启动.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.AddApplicationInsightsTelemetry(Configuration["ApplicationInsights:ConnectionString"]);
}
应用设置.json
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"ApplicationInsights": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Information"
},
"ConnectionString": "InstrumentationKey=*****;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com/"
},
代码:
public async Task SendMessageAsync()
{
...
using (this._logger.BeginScope(nameof(SendMessageAsync)))
{
...
_logger.LogInformation($"Message sent...");
...
}
}
在 VS 输出中,我看到正在记录信息消息,但没有看到 LogInformation 的 AppInsights 遥测
SenderApp.Controllers.HomeController: Information: Message sent...
Application Insights Telemetry: {"name":"AppDependencies","time":...
Application Insights Telemetry: {"name":"AppDependencies","time":...
解决方案
答案很简单,但不容易调试。
AppInsights 的日志记录设置appsettings.josn
应位于Logging
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Information",
"Microsoft.Hosting.Lifetime": "Information"
},
"ApplicationInsights": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Information"
}
}
},
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=*****;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com/"
}
推荐阅读
- django - django + restframework如何通过继承类实现参数接口
- java - 我的 android studio 代码构建成功但输出应用程序崩溃
- c++ - 最后一个 0 是文字吗?
- mysql - 如何使用laravel在数据库中上传多个文件
- php - 它是如何工作的静态方法和变量
- css-grid - 点亮元素 css 网格
- html - Cypress mochawesome 报告
- flutter - 在 Flutter 中为 IOS 和 ANDROID 初始化 Firebase
- c - 如何在 C 中将 short 转换为 unsigned char *buf?
- python-3.x - 如何在python中将像素化图像转换为高质量图像?