question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow an array-style config format for Serilog:MinimumLevel:Override

See original GitHub issue

At the moment, the way you specify Serilog’s minimum level overrides in configuration is in the following format:

"MinimumLevel": {
	"Default": "Information",
	"Override": {
		"Microsoft.AspNetCore.Mvc.Infrastructure": "Debug",
		"Microsoft": "Warning",
		"Microsoft.Hosting.Lifetime": "Information",
		"Microsoft.AspNetCore.Authentication": "Verbose",
	}
}

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:

"Serilog:MinimumLevel:Override:Microsoft_AspNetCore_Mvc_Infras": "Debug"

On my local machine, which is using appsettings.json, this is how it (correctly) looks:

"Serilog:MinimumLevel:Override:Microsoft.AspNetCore.Mvc.Infrastructure": "Debug"

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:

"MinimumLevel": {
	"Default": "Information",
	"Override": [
		{
			"SourceContext": "Microsoft.AspNetCore.Mvc.Infrastructure",
			"Level": "Debug"
		},
		{
			"SourceContext": "Microsoft",
			"Level": "Warning"
		},
		{
			"SourceContext": "Microsoft.Hosting.Lifetime",
			"Level": "Information"
		},
		{
			"SourceContext": "Microsoft.AspNetCore.Authentication",
			"Level": "Verbose"
		}
	]
}

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:

"Serilog:MinimumLevel:Override:0:SourceContext": "Microsoft.AspNetCore.Mvc.Infrastructure"
"Serilog:MinimumLevel:Override:0:Level": "Debug"

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
skomis-mmcommented, Mar 29, 2020

New syntax other than adding more verbosity won’t do any better for environment variables. For one level override: MinimumLevel__Override__0__SourceContext=Microsoft.AspNetCore.Mvc.Infrastructure MinimumLevel__Override__0__Level=Debug

  1. Still need to use underscores for some platforms
  2. Need to use array indexes elements in the key names which are fragile to use
  3. 2 variables for one override instead of 1

We have an old issue to overcome current current syntax and simplify it, not to add complexity to it.

3reactions
nblumhardtcommented, Mar 29, 2020

I think any issue Serilog suffers here is going to be shared by Microsoft.Extensions.Logging, which uses the same layout for overrides, so hopefully the Azure web app limitation will be spotted and lifted by the good folks at Microsoft. Raising an issue with them might speed this along, @jez9999.

Adding more variations to the configuration syntax makes it more complicated to define, document, and learn, hence @skomis-mm’s concern about UX, I think.

We don’t have the time here for the “nonsense”, “so what?” combative style of communication; it drains the energy out of open source projects. I’ve responded to similar recent comments here and here. Life’s too short for more of this, let’s start afresh if necessary, closing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Allow an array-style config format for Serilog ...
Currently, if App Setting names are longer than 64 characters, only the first 64 characters of the environment variable will be imported into ......
Read more >
Overriding MinimumLevel doesn't work in Serilog
You are overriding the MinimumLevel only for log messages sent from a SourceContext with the name LogTest , as per your configuration.
Read more >
Serilog 2.1 MinimumLevel.Override()
The Serilog MinimumLevel setting determines at which level log events are generated: Log.Logger = new LoggerConfiguration() .MinimumLevel ...
Read more >
How to prevent serilog from logging sensitive data such as ...
I have read a lot of serilog documentations and gone through stackoverflow suggestions but I can't seem to figure out how to prevent...
Read more >
Serilog Settings
ReadFrom : A way of applying configuration to the log configuration, common examples include from configuration files. WriteTo : The way sinks are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found