1
0
Форкнуть 0

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:
davidnx 2019-07-08 09:52:43 -07:00 коммит произвёл Cijo Thomas
Родитель d1e2620ea7
Коммит 8753a25e35
1 изменённых файлов: 15 добавлений и 10 удалений

Просмотреть файл

@ -227,20 +227,25 @@
// 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);
// However, this will make it impossible to override this behavior from Configuration like below using appsettings.json:
// "ApplicationInsights": {
// "LogLevel": {
// "": "Error"
// {
// "Logging": {
// "ApplicationInsights": {
// "LogLevel": {
// "": "Error"
// }
// }
// },
// ...
// }
// },
// 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,
// we add code filter rule to the 0th position as below.
loggingBuilder.Services.Configure<LoggerFilterOptions>(
options => options.Rules.Insert(
0,
new LoggerFilterRule(
"Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider", null,
LogLevel.Warning, null)));
loggingBuilder.Services.Configure<LoggerFilterOptions>(
options => options.Rules.Insert(
0,
new LoggerFilterRule(
"Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider", null,
LogLevel.Warning, null)));
});
#endif
}