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
{{ message }}
Repository navigation
Cannot create environment variable for logging category with periods #87130
The logging and configuration docs agree on creating environment variables for deep configuration structures.
Logging__LogLevel__Microsoft=Information
But, you can't use a period in a variable or environment variable name in any shell that I know of. It's not disallowed by the spec, apparently, but the various shells seem to avoid period in their implementations.
changed the title [-]Cannot create environment variable for namespace category with periods[/-][+]Cannot create environment variable for logging category with periods[/+]on Feb 12, 2021
@IEvangelist@Rick-Anderson do you have an idea as to the answer? What does the environment variable system use to replace . when the setting contains a .?
The environment variable provider doesn't give special treatment to a .: It only substitutes __ for :. @Rick-Anderson and I looked into this before, but couldn't find a way to make this particular setup work. I can't see that anything has changed here, either.
While this is a good question and fair observation to call attention to it, I do not believe it is a problem. Logging is the only example that I'm aware that has namespaces or various patterns like this within their configuration settings. And since it is logging, there is no real value in keeping it a secret, or securing it away in an environment variable - you know? I'd argue that is should remain in an appsettings.json file.
@IEvangelist fair points... but, we're not supposed to use environment variables for secrets (and that's not the only reason they're used, see DOTNET_ENVIRONMENT and others) and we don't always have an easy way to override or provide an appsettings file (thinking some CI/CD scenarios where your "services" like linked containers syntax is limited).
I've been testing it a lot this morning (I can confirm that does work), I'm updating the article to also include cross-plat env var setting with notes/link to the SE bits I stumbled upon. See proposed changes here.
I think this needs to be evaluated again, specifically for apps running in containers. We are not able to set an environment variable that contains a period for a container. So, we are not able to configure logging upon deployment. In our case we only want to turn on Informational logging for a specific library, so not to flood the logs.
Reacted by Jason Talon, Alexandre Bossard, Scott Merkling and Graham Scanlon
I've ran into exactly that this morning. We have a local development setup that overrides the appsettings through environment. It works with every variables but the log levels, which is quite ridiculous. While working with containers, you want to test your environment variables does not contain typos.
Would it be possible to translate the log levels '.' in '__' just like the ':' ?
@IEvangelist this issue is not resolved, I reviewed your doc update and it did not cover anything about what everyone is stating does not work. And that is, using periods in environment variable names. Surrounding the entire my.var.name=value with quotes as you describe as a workaround only works in shell environments, and not with things like Kubernetes deployments.
Hi @johnwc, Thanks for the follow-up. If that is the case, I'm not sure if this is a docs issue, it might need to get transferred to the product team if you believe that they'll need to change how env vars are parsed. Let's ask @maryamariyan, she might know.
We are running into a similar issue. We are running into a kubernetes environment and there is no way to configure the LogLevel for anything within a subsystem (e.g. this does not work Logging__LogLevel__System.Net.Http.HttpClient=Warning. Trying to change this value with appsettings.json requires a change that goes through the entire CICD pipeline, rather than a configuration change that can be done at runtime as needed for production debugging (i.e. temporarily changing the LogLevel of a service to get more information).
Can this issue be re-opened?
Reacted by John Carew, Victor Brito, Kamil Adamus, Alexey Shibanov, Rui Garcia and joao-genebra
We are also running into this issue.
Our existing deployment strategy relies on environment variables to change the logging levels which means using appsettings.json would bring a lot more complexity into our solution. It really feels like environment variables should have a different strategy for representing . so that we can safely setup logging levels for different categories without having to worry about special characters in any of the systems that handle them.
Hi @johnwc and others, I transferred this issue to the dotnet/runtime repo as this is a product issue. I believe that they'll need to update the code itself to handle the desired substitution.
Reacted by John Carew
ghost added
untriagedNew issue has not been triaged by the area owner
We are currently tracking the same issue under #35989. I will proceed to close this particular issue, but please feel free to respond here or on the linked issue if you have any further questions or require assistance.
Please note that this is a feature request that can only be implemented in a future release. However, I can provide you with a workaround code that you can utilize in your application to temporarily resolve the issue until it is officially supported by the framework. The workaround involves creating a custom configuration provider to handle the replacement of dots in the environment variable. This workaround serves as an extension to the environment variable configuration provider, making it straightforward to implement by replacing the call to IConfigurationBuilder.AddEnvironmentVariables() with the new custom method, IConfigurationBuilder.AddCustomEnvironmentVariables().
Activity
[-]Cannot create environment variable for namespace category with periods[/-][+]Cannot create environment variable for logging category with periods[/+]adegeo commentedon Feb 18, 2021
@IEvangelist @Rick-Anderson do you have an idea as to the answer? What does the environment variable system use to replace
.when the setting contains a.?Rick-Anderson commentedon Feb 18, 2021
@serpent5 can probably figure it out.
serpent5 commentedon Feb 18, 2021
The environment variable provider doesn't give special treatment to a
.: It only substitutes__for:. @Rick-Anderson and I looked into this before, but couldn't find a way to make this particular setup work. I can't see that anything has changed here, either.IEvangelist commentedon Feb 18, 2021
While this is a good question and fair observation to call attention to it, I do not believe it is a problem. Logging is the only example that I'm aware that has namespaces or various patterns like this within their configuration settings. And since it is logging, there is no real value in keeping it a secret, or securing it away in an environment variable - you know? I'd argue that is should remain in an appsettings.json file.
AnthonyMastrean commentedon Feb 19, 2021
@IEvangelist fair points... but, we're not supposed to use environment variables for secrets (and that's not the only reason they're used, see DOTNET_ENVIRONMENT and others) and we don't always have an easy way to override or provide an appsettings file (thinking some CI/CD scenarios where your "services" like linked containers syntax is limited).
IEvangelist commentedon Feb 19, 2021
I was able to set an environment variable locally in my bash environment with this name (based on this SO), it just needed quotes around it:
env "Logging__LogLevel__Microsoft.Hosting.Lifetime=Information"I confirmed that I see it in the env vars too.
AnthonyMastrean commentedon Feb 19, 2021
Good find, thanks!
Rick-Anderson commentedon Feb 19, 2021
Can you set it to
env "Logging__LogLevel__Microsoft.Hosting.Lifetime=Error"and verify it's working?
Nice work @IEvangelist
IEvangelist commentedon Feb 19, 2021
I've been testing it a lot this morning (I can confirm that does work), I'm updating the article to also include cross-plat env var setting with notes/link to the SE bits I stumbled upon. See proposed changes here.
johnwc commentedon Jul 3, 2022
I think this needs to be evaluated again, specifically for apps running in containers. We are not able to set an environment variable that contains a period for a container. So, we are not able to configure logging upon deployment. In our case we only want to turn on Informational logging for a specific library, so not to flood the logs.
AlexandreBossard commentedon Sep 27, 2022
I've ran into exactly that this morning. We have a local development setup that overrides the appsettings through environment. It works with every variables but the log levels, which is quite ridiculous. While working with containers, you want to test your environment variables does not contain typos.
Would it be possible to translate the log levels '.' in '__' just like the ':' ?
5 remaining items
LordMike commentedon Mar 28, 2023
See also dotnet/AspNetCore.Docs#17378 -
systemdalso does not allow dots in env names.johnwc commentedon Mar 29, 2023
@IEvangelist this issue is not resolved, I reviewed your doc update and it did not cover anything about what everyone is stating does not work. And that is, using periods in environment variable names. Surrounding the entire
my.var.name=valuewith quotes as you describe as a workaround only works in shell environments, and not with things like Kubernetes deployments.@Rick-Anderson @IEvangelist can you please reopen this issue?
IEvangelist commentedon Mar 29, 2023
Hi @johnwc, Thanks for the follow-up. If that is the case, I'm not sure if this is a docs issue, it might need to get transferred to the product team if you believe that they'll need to change how env vars are parsed. Let's ask @maryamariyan, she might know.
pbstrein commentedon Apr 13, 2023
We are running into a similar issue. We are running into a kubernetes environment and there is no way to configure the LogLevel for anything within a subsystem (e.g. this does not work
Logging__LogLevel__System.Net.Http.HttpClient=Warning. Trying to change this value withappsettings.jsonrequires a change that goes through the entire CICD pipeline, rather than a configuration change that can be done at runtime as needed for production debugging (i.e. temporarily changing the LogLevel of a service to get more information).Can this issue be re-opened?
rbgarcia commentedon Jun 2, 2023
We are also running into this issue.
Our existing deployment strategy relies on environment variables to change the logging levels which means using
appsettings.jsonwould bring a lot more complexity into our solution. It really feels like environment variables should have a different strategy for representing.so that we can safely setup logging levels for different categories without having to worry about special characters in any of the systems that handle them.johnwc commentedon Jun 3, 2023
@IEvangelist it's been a few months now with no response from @maryamariyan or product team. How can we get better attention for this issue?
IEvangelist commentedon Jun 5, 2023
Hi @johnwc and others, I transferred this issue to the dotnet/runtime repo as this is a product issue. I believe that they'll need to update the code itself to handle the desired substitution.
tarekgh commentedon Jun 9, 2023
We are currently tracking the same issue under #35989. I will proceed to close this particular issue, but please feel free to respond here or on the linked issue if you have any further questions or require assistance.
Please note that this is a feature request that can only be implemented in a future release. However, I can provide you with a workaround code that you can utilize in your application to temporarily resolve the issue until it is officially supported by the framework. The workaround involves creating a custom configuration provider to handle the replacement of dots in the environment variable. This workaround serves as an extension to the environment variable configuration provider, making it straightforward to implement by replacing the call to
IConfigurationBuilder.AddEnvironmentVariables()with the new custom method,IConfigurationBuilder.AddCustomEnvironmentVariables().Using that, now you can define the environment variable with three underscores
___in the places you want dot.