Repository navigation
Description
Currently EnvironmentVariablesConfigurationProvider replaces __ with :.
I propose to do something similar for dot.
Use case:
I need to configure logging in an asp.net core app hosted in Azure Container Instance.
I want to set one specific logger to Trace, so I need to set the configuration key Logging:LogLevel:Company.Namespace.MyCustomMiddleware = Trace.
Locally on my windows PC I can run
set Logging__LogLevel__Company.Namespace.MyCustomMiddleware=Trace
and everything works.
When I try to do it in Azure App Service, it doesn't allow me to create the container, even though it is a windows container:
Request: Please add a replacement for ., similar to :.
Workaround: I can do a code change to change the name of the logger, this works as long as it is first party code, not third party.
This section is added by @tarekgh
API Proposal
Here is the API can be used to address this issue nicely:
Proposal
namespace Microsoft.Extensions.Configuration.EnvironmentVariables
{
public partial class EnvironmentVariablesConfigurationSource : IConfigurationSource
{
// NEW: A string that, when found in env var keys, is replaced with "."
// Default is null (no replacement, backward compatible)
public string? DotReplacement { get; set; }
}
}
// EnvironmentVariablesConfigurationProvider — new constructor overload
namespace Microsoft.Extensions.Configuration.EnvironmentVariables
{
public partial class EnvironmentVariablesConfigurationProvider : ConfigurationProvider
{
// NEW
public EnvironmentVariablesConfigurationProvider(string? prefix, string? dotReplacement) { }
}
}Usage:
builder.Configuration.AddEnvironmentVariables(source =>
{
source.DotReplacement = "_._";
});Alternative design
This is more flexible but less discoverable.
namespace Microsoft.Extensions.Configuration.EnvironmentVariables
{
public partial class EnvironmentVariablesConfigurationSource : IConfigurationSource
{
// NEW: Custom key normalizer; if null, uses default __ → : behavior
public Func<string, string>? KeyNormalizer { get; set; }
}
}
Activity
[-]Add a replacement for dot in EnvironmentVariablesConfigurationProvider[/-][+][Feature Request] Add a replacement for dot in EnvironmentVariablesConfigurationProvider[/+]analogrelay commentedon Jan 23, 2020
Putting in the list of possible 5.0 candidates (no guarantees!). The fact that logging can't be fully configured via environment variables because of this is a compelling reason to consider this.
analogrelay commentedon Apr 24, 2020
Triage: We think the right approach here is to see if App Service can resolve this blockage. Adding a new replacement pattern would be extremely breaking.
analogrelay commentedon Apr 24, 2020
Turns out macOS and Linux don't support
.in env vars either though, so we may need to find a deeper solution for the Logging problem specifically. The problem is it's also breaking to use a replacement token in Logging because logger names can be any string (they tend to be based on type names but don't have to be).ericstj commentedon Apr 24, 2020
There appear to be lots of characters that aren't allowed here. Here are some that I tried:
#^+&|;,does this require some generic escaping rule?42 remaining items
rosebyte commentedon Mar 2, 2026
Triage: the issue here is that platforms may reserve any character and users know better what they need to achieve than we can support in general framework, so it seems better to follow a workaround proposed by @tarekgh in another issue (#87130 (comment)). With appropriate context, it's easy to replace dots, commas, colons, dashes etc. in a way that won't collide with anything, in a framework supporting everyone, it's not.
jez9999 commentedon Mar 2, 2026
Sorry, but this is a really silly decision. When you're working on some small program to go on an Azure instance or something you shouldn't need to write a custom
EnvironmentVariablesConfigurationProviderjust to be able to use a dot in a config setting! There are some very common config settings in .NET itself that need dot in particular (making it special), and whilst "platforms may reserve any character", we all know Linux is extremely popular as a server platform and so is important to take into consideration. I'd strongly suggest you reopen this.svick commentedon Mar 4, 2026
I have created API proposal #125137 that I believe better addresses this issue, so I'm going to close this one. Feel free to comment there.
Dreamescaper commentedon Mar 17, 2026
IMHO, there's questionable need for generic solution here (#125137). I would say that most of examples I saw here are about Logging categories.
I would say that even handling it on logging side (treat _ as . when filtering categories) would resolve 99% of requests for this functionality.
jez9999 commentedon Mar 17, 2026
Why not have a generic solution here, though? It's not hard to whip up some code that reads
DOTNETVARxand treats them as x=y config values. Probably only needs a handful of tests.Dreamescaper commentedon Mar 17, 2026
I'm fine with generic solution, as long as I don't have to change anything in code for it to work.
I don't like #125137 because I need to change code to set VariableNameTransformation beforehand. It shoudn't be needed just to be able to change logLevel via env variable.