Created
October 20, 2021 05:29
-
-
Save WernerMairl/a26a3df8013c4f8a87da79a16f8ce24e to your computer and use it in GitHub Desktop.
WebHost with Environment fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var builder = Host.CreateDefaultBuilder(args) | |
.ConfigureWebHostDefaults( | |
webBuilder => | |
{ | |
webBuilder | |
.UseStartup<Startup>() | |
.ConfigureAppConfiguration(app => | |
{ | |
var finding = app.Sources.Where(s => s is EnvironmentVariablesConfigurationSource).SingleOrDefault() as EnvironmentVariablesConfigurationSource; | |
if (finding != null) | |
{ | |
int oldIndex = app.Sources.IndexOf(finding); | |
var newSource = new ExtendedEnvironmentVariablesConfigurationSource(); | |
newSource.NormalizeKeyCallback = (key) => | |
{ | |
int logLevelIndex = key.IndexOf("LogLevel:", StringComparison.InvariantCultureIgnoreCase); | |
if (logLevelIndex > -1) | |
{ | |
return key.Replace("_", "."); | |
} | |
return key; | |
}; | |
app.Sources[oldIndex] = newSource; | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment