-
Notifications
You must be signed in to change notification settings - Fork 131
Allow an array-style config format for Serilog:MinimumLevel:Override #214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
So where did you hit "61 characters limit" on key names? Can you make a repro steps? Or is having "dots" in namespace name is the only reason for a new syntax? |
Looks like it's actually 64 characters. To repro:
|
Fixed by #212 |
Thanks. So it is Linux Web App running-in-container limitation. Need think about it. Here the link for a reference: |
The key word public static class Extensions
{
public static LoggerConfiguration ApplyCustomOverrides(this LoggerConfiguration cfg, IConfigurationSection section)
=> section.GetChildren().Aggregate(cfg, (c, s) => c.MinimumLevel.Override(s.GetValue<string>("SourceContext"), s.GetValue<LogEventLevel>("Level")));
} Config: "MinimumLevel": {
"Default": "Information",
"OverrideList": [
{
"SourceContext": "Microsoft.AspNetCore.Mvc.Infrastructure",
"Level": "Debug"
},
{
"SourceContext": "Microsoft",
"Level": "Warning"
},
{
"SourceContext": "Microsoft.Hosting.Lifetime",
"Level": "Information"
},
{
"SourceContext": "Microsoft.AspNetCore.Authentication",
"Level": "Verbose"
}
]
} Usage: var logger = new LoggerConfiguration()
.ApplyCustomOverrides(configuration.GetSection("Serilog:MinimumLevel:OverrideList"))
.ReadFrom.Configuration(configuration)
.CreateLogger(); |
How do you know it's a matter of time? |
Starting afresh because the other issue was closed.
At the moment, the way you specify Serilog's minimum level overrides in configuration is in the following format:
The source context (or 'namespace') is specified in the setting name, rather than a value. The trouble with this is that not all configuration providers lend themselves to having long, complex configuration key names. For example, I've tried to configure the equivalent to this on an Azure web app (using the double-underscore namespace separator as a replacement for the colon), and the best I could get to was:
On my local machine, which is using
appsettings.json
, this is how it (correctly) looks:The dots have been replaced with underscores, and more importantly there is a very restrictive length limit on config key names from these environment variables. So I think the solution is not to try and put complex/long information like a namespace in the key name, but as a key value. Thus, I propose that Serilog support the following syntax for minimum level overrides:
When Override is an array, it takes a set of objects with SourceContext/Level that specify the override level for the given source context. This results in the following kind of config structure, which works even with config providers that have restrictive key names:
The text was updated successfully, but these errors were encountered: