Я смотрю на appsettings.json из Пример проекта Serilog, который имеет следующий фрагмент:
"MinimumLevel": {
"Default": "Debug",
"Override": {
"System": "Information",
"Microsoft": "Information"
}
}
В этом контексте, какова цель Override? Записи System и Microsoft не имеют родительской настройки в узле MinimumLevel, так что же она переопределяет?
Если только я не совсем понимаю цель Override.





По умолчанию вы говорите, что любая запись журнала с уровнем серьезности «Отладка» или выше должна быть отправлена на ваш приемник (консоли, файлы и т. д.).
Это похоже на поведение Документ Microsoft по ведению журнала:
For example, logging configuration is commonly provided by the
Loggingsection of app settings files. The following example shows the contents of a typical appsettings.Development.json file:{ "Logging": { "LogLevel": { "Default": "Debug", "System": "Information", "Microsoft": "Information" }, "Console": { "IncludeScopes": true } } }[...]
The
LogLevelproperty underLoggingspecifies the minimum level to log for selected categories. In the example,SystemandMicrosoftcategories log atInformationlevel, and all others log atDebuglevel.
Разделы переопределения предназначены для изменения записей журнала, которые имеют эти пространства имен. Обычно вы хотите видеть записи журнала Debug для ваш код, но более высокий уровень (например, Information или Warning) для «не вашего кода», например Microsoft и System.
Вместо того, чтобы помещать эту конфигурацию в файл конфигурации, вы также можете использовать код:
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseSerilog((ctx, cfg) =>
{
cfg.ReadFrom.Configuration(ctx.Configuration)
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information);
})
.Build();
Code from kimsereyblog.blogspot.com
Их объяснение процесса таково:
From the example we saw that we can configure a default minimum level of logging
.MinimumLevel.Debug(). We can also override that default for certain namespaces, for example here we set the minimum level of logging forMicrosoftnamespace toInformation. This will prevent ASP.NET Core to log all debug logs while keeping our own debug logs.
Другое объяснение от nblumhardt.com:
The first argument of
Overrideis a source context prefix, which is normally matched against the namespace-qualified type name of the class associated with the logger....
The effect of the configuration above, then, is to generate events only at or above the
Warninglevel when the logger is owned by a type in aMicrosoft.*namespace.