Skip to content

Instantly share code, notes, and snippets.

@WernerMairl
Created October 20, 2021 05:29
Show Gist options
  • Save WernerMairl/a26a3df8013c4f8a87da79a16f8ce24e to your computer and use it in GitHub Desktop.
Save WernerMairl/a26a3df8013c4f8a87da79a16f8ce24e to your computer and use it in GitHub Desktop.
WebHost with Environment fix
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