You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to make an app that has a default console output format (With an OutputTemplate), but is otherwise overridable by configs (environment variables in my case).
I've made an example app to show my issue. I have a config like this:
So far so good.
Now I want my users to use environment variables (or something else) to override the configs, and potentially use a custom formatter, like RenderedCompactJsonFormatter. So we add in environment variables to our config builder, and add the following:
But this doesn't override the OutputTemplate, it still outputs My custom template - if I remove the OutputTemplate from the config json (using the default from the Console sink), the environment variable works - it switches to json rendering.
I've also tried overriding the template with a blank string, like:
Logging__WriteTo__0__Args__OutputTemplate: ""
.. but this just changes the output template to a blank string - it's still used.
From what I read, Microsoft.Extensions.Configuration doesn't support unsetting values, you cannot f.ex. configure a specific key to null, and have it removed from the system. The closest you can get, is overriding a value with a blank string, and have that be a convention to be "unset". For example, this blog post also highlights the issue:
I mentioned overriding with an empty string as a “fake way” to remove configuration. Specifying null as a value, even in JSON config, doesn’t work. It reads the value and uses an empty string as the value instead of null. Further, there’s no XML analogy to null, nor are there such analogies in most other providers.
Given everything in the config system is a key/value string pair, the closest you can get, then, is to set things to empty strings. When you read values, check for String.IsNullOrEmpty() before using the value.
Are there any tips on how I can provide a custom default template, but let users override my config using Microsofts configuration system?
Should I focus on skipping my default template, and leave it unset from the beginning?
Should I add a PR to this repo, that checks if a value from Microsoft.Extensions.Configuration is String.Empty, and consider it "null" ?
Should I add a PR to Serilog, specifically to ignore the settings set and use the formatter if the formatter is set (so it takes precedence)?
I think I'm going with skipping the custom format by default, in order to let users override the formatter - but I think there might be a general issue here :).
The text was updated successfully, but these errors were encountered:
I'm trying to make an app that has a default console output format (With an
OutputTemplate
), but is otherwise overridable by configs (environment variables in my case).I've made an example app to show my issue. I have a config like this:
I can then use it:
Which outputs
So far so good.
Now I want my users to use environment variables (or something else) to override the configs, and potentially use a custom formatter, like
RenderedCompactJsonFormatter
. So we add in environment variables to our config builder, and add the following:But this doesn't override the OutputTemplate, it still outputs
My custom template
- if I remove theOutputTemplate
from the config json (using the default from the Console sink), the environment variable works - it switches to json rendering.I've also tried overriding the template with a blank string, like:
.. but this just changes the output template to a blank string - it's still used.
From what I read, Microsoft.Extensions.Configuration doesn't support unsetting values, you cannot f.ex. configure a specific key to null, and have it removed from the system. The closest you can get, is overriding a value with a blank string, and have that be a convention to be "unset". For example, this blog post also highlights the issue:
Are there any tips on how I can provide a custom default template, but let users override my config using Microsofts configuration system?
String.Empty
, and consider it "null" ?I think I'm going with skipping the custom format by default, in order to let users override the formatter - but I think there might be a general issue here :).
The text was updated successfully, but these errors were encountered: