我们发现对 ILogger.LogInformation("text message") 的调用似乎没有执行任何操作 - 例如,代码中没有包含“text message”的 AppInsights 条目。
不确定这是为什么 - 我们是否需要显式指定日志级别(目前不需要)或者是否需要打开 Azure 设置?还有什么可以看的吗
这是program.cs中的引导代码 - 没有什么不寻常的:
builder.ConfigureWebJobs((context, b) =>
{
b.AddTimers();
b.AddAzureStorageCoreServices();
b.AddAzureStorage();
})
.ConfigureLogging((context, b) =>
{
b.AddConfiguration(context.Configuration);
b.AddSimpleConsole(c =>
{
c.TimestampFormat = "[yyyy-MM-dd HH:mm:ss UTC] ";
c.UseUtcTimestamp = true;
});
var appInsightsKey = context.Configuration["APPINSIGHTS_INSTRUMENTATIONKEY"];
if (!string.IsNullOrWhiteSpace(appInsightsKey))
{
b.AddApplicationInsightsWebJobs(o => { o.InstrumentationKey = appInsightsKey; });
}
b.AddAzureWebAppDiagnostics();
});
调用 ILogger.LogInformation() 的代码位于调解器处理程序中。它没有什么异国情调,所以不会在这里包含它。以下是 Nuget 软件包和版本号:
我们是否需要显式指定日志级别(目前不需要)是的,你知道。默认日志级别为警告。请参阅
文档:
Application Insights 的默认设置是仅捕获警告和更严重的日志。您可以在设置中配置默认日志级别:
{
"Logging": {
"LogLevel": {
"Default": "Information"
},
"ApplicationInsights": {
"LogLevel": {
"Default": "Information"
}
}
},
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=00000000-0000-0000-0000-000000000000"
}
}