Skip to content

Commit 399feaa

Browse files
authored
Update ReadMe.md
1 parent f6a549c commit 399feaa

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

ReadMe.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -390,18 +390,23 @@ var builder = new HostBuilder();
390390

391391
// set the content root to executing assembly's location.
392392
builder.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+
393406
builder.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+
422428
builder.ConfigureLogging(logging =>
423429
{
424430
// if embeded SimpleConsoleLogger(default is true), setup logging(MinLogLevel's default is Debug).

0 commit comments

Comments
 (0)