鉴于此 appsettings.json
{
"ApplicationInsights": {
"InstrumentationKey": "foobar",
"LogLevel": {
"Default": "Debug"
}
},
"Logging": {
"LogLevel": {
"Default": "Debug"
}
},
"AllowedHosts": "*"
}
这来自 startup.cs
public void ConfigureServices(IServiceCollection services)
{
var appSettingsSection = Configuration.GetSection("TD");
var appSettings = new AppSettings();
new ConfigureFromConfigurationOptions<AppSettings>(appSettingsSection).Configure(appSettings);
services.Configure<AppSettings>(appSettingsSection);
services.AddApplicationInsightsTelemetry();
services.AddTransient<IMyService, MyService>();
services.AddControllersWithViews();
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp";
});
}
为什么我在 AI 输出中仍然只看到严重、错误和警告?
例如来自 Controller 的任意日志
public async Task<IActionResult> MyAction(string foobar)
{
Logger.LogDebug($"Ilogger debug {foobar}");
Logger.LogInformation($"Ilogger info {foobar}");
Logger.LogWarning($"Ilogger warning {foobar}");
Logger.LogError($"Ilogger error {foobar}");
Logger.LogCritical($"Ilogger critical {foobar}");
}
根据微软文档here
ApplicationInsightsLoggerProvider is enabled by default in Microsoft.ApplicationInsights.AspNet SDK version 2.7.1 (and later) when you turn on regular Application Insights monitoring through either of the methods:
- By calling the UseApplicationInsights extension method onIWebHostBuilder (Now obsolete)
- By calling the AddApplicationInsightsTelemetry extension method on IServiceCollection
所以我有点不明白为什么没有输出调试/信息跟踪。
appsettings.development.json 中没有覆盖或日志记录设置。
我使用的是 AppInsights SDK 2.13.1。
Asp NET Core 3.1。
最佳答案
appsettings.json
有问题(如果您确定没有其他地方覆盖日志记录级别)。应用程序洞察的日志级别应放置在 .json 文件中的 Logging
元素内(请参阅官方文档 here )。
正确的应该是这样的:
{
"ApplicationInsights": {
"InstrumentationKey": "xxxxx"
},
"Logging": {
"LogLevel": {
"Default": "Debug"
},
"ApplicationInsights": {
"LogLevel": {
"Default": "Debug"
}
}
},
"AllowedHosts": "*"
}
测试结果:
关于azure - ApplicationInsights 不考虑 json 配置的日志级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60928341/