@@ -390,18 +390,23 @@ var builder = new HostBuilder();
390390
391391// set the content root to executing assembly's location.
392392builder .UseContentRoot (Path .GetDirectoryName (Assembly .GetExecutingAssembly ().Location ));
393+
394+ // set the host configuration
395+ builder .ConfigureHostConfiguration (config =>
396+ {
397+ config .AddEnvironmentVariables (prefix : " NETCORE_" );
398+ config .AddInMemoryCollection (new [] { new KeyValuePair <string , string >(HostDefaults .ApplicationKey , Assembly .GetExecutingAssembly ().GetName ().Name ) });
399+ });
400+
401+ if (! string .IsNullOrWhiteSpace (hostEnvironmentVariable ))
402+ {
403+ builder .UseEnvironment (System .Environment .GetEnvironmentVariable (hostEnvironmentVariable ) ?? " Production" );
404+ }
405+
393406builder .ConfigureAppConfiguration ((hostingContext , config ) =>
394407{
395408 var env = hostingContext .HostingEnvironment ;
396409
397- // Get/Set Environement Name.
398- env .ApplicationName = Assembly .GetExecutingAssembly ().GetName ().Name ;
399- if (string .IsNullOrWhiteSpace (contextEnvironmentVariable ))
400- {
401- contextEnvironmentVariable = " NETCORE_ENVIRONMENT" ;
402- }
403- env .EnvironmentName = System .Environment .GetEnvironmentVariable (contextEnvironmentVariable ) ?? " Production" ;
404-
405410 // Load settings from JSON file.
406411 config .AddJsonFile (" appsettings.json" , optional : true , reloadOnChange : true );
407412 config .AddJsonFile ($" appsettings.{env .EnvironmentName }.json" , optional : true , reloadOnChange : true );
@@ -419,6 +424,7 @@ builder.ConfigureAppConfiguration((hostingContext, config) =>
419424 // Load settings from Environment variables.
420425 config .AddEnvironmentVariables ();
421426});
427+
422428builder .ConfigureLogging (logging =>
423429{
424430 // if embeded SimpleConsoleLogger(default is true), setup logging(MinLogLevel's default is Debug).
0 commit comments