Improve slightly misleading comment for beginners (#916)
The comment about how to override the LogLevel in appsettings.json did not make it clear that the required keys must appear within `Logging` in appsettings.json.
This commit is contained in:
Родитель
d1e2620ea7
Коммит
8753a25e35
|
@ -227,20 +227,25 @@
|
||||||
// The default behavior is to capture only logs above Warning level from all categories.
|
// The default behavior is to capture only logs above Warning level from all categories.
|
||||||
// This can achieved with this code level filter -> loggingBuilder.AddFilter<Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider>("",LogLevel.Warning);
|
// This can achieved with this code level filter -> loggingBuilder.AddFilter<Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider>("",LogLevel.Warning);
|
||||||
// However, this will make it impossible to override this behavior from Configuration like below using appsettings.json:
|
// However, this will make it impossible to override this behavior from Configuration like below using appsettings.json:
|
||||||
// "ApplicationInsights": {
|
// {
|
||||||
// "LogLevel": {
|
// "Logging": {
|
||||||
// "": "Error"
|
// "ApplicationInsights": {
|
||||||
|
// "LogLevel": {
|
||||||
|
// "": "Error"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// ...
|
||||||
// }
|
// }
|
||||||
// },
|
|
||||||
// The reason is as both rules will match the filter, the last one added wins.
|
// The reason is as both rules will match the filter, the last one added wins.
|
||||||
// To ensure that the default filter is in the beginning of filter rules, so that user override from Configuration will always win,
|
// To ensure that the default filter is in the beginning of filter rules, so that user override from Configuration will always win,
|
||||||
// we add code filter rule to the 0th position as below.
|
// we add code filter rule to the 0th position as below.
|
||||||
loggingBuilder.Services.Configure<LoggerFilterOptions>(
|
loggingBuilder.Services.Configure<LoggerFilterOptions>(
|
||||||
options => options.Rules.Insert(
|
options => options.Rules.Insert(
|
||||||
0,
|
0,
|
||||||
new LoggerFilterRule(
|
new LoggerFilterRule(
|
||||||
"Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider", null,
|
"Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider", null,
|
||||||
LogLevel.Warning, null)));
|
LogLevel.Warning, null)));
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче