private static string GetEnvironmentTypeName()
        {
            string result = Environment.GetEnvironmentVariable(EnvironmentVariables.GetEnvironmentVariableKey(EnvironmentVariableKey.AspNetCoreEnvironment));

            if (string.IsNullOrWhiteSpace(result))
            {
                throw new MissingEnvironmentVariableException($"The following Environment Variable does not exist with this key. {nameof(EnvironmentVariableKey).ToUpper()}: {EnvironmentVariableKey.AspNetCoreEnvironment}");
            }

            return(result);
        }
Beispiel #2
0
        public App()
        {
            _host = new HostBuilder()
                    .ConfigureHostConfiguration(builder =>
            {
                KeyValuePair <string, string> environment = new(HostDefaults.EnvironmentKey,
                                                                Environment.GetEnvironmentVariable(EnvironmentVariables.GetEnvironmentVariableKey(EnvironmentVariableKey.AspNetCoreEnvironment)));

                builder.AddInMemoryCollection(new[] { environment })
                .AddEnvironmentVariables();
            })
                    .ConfigureAppConfiguration(builder =>
            {
                builder.SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
            })
                    .ConfigureServices((context, services) =>
            {
                ConfigureServices(context.HostingEnvironment, context.Configuration, services);
            })
                    .ConfigureLogging((context, logging) =>
            {
                logging.ClearProviders();
                logging.SetMinimumLevel(LogLevel.Trace);
                logging.AddNLog(context.Configuration);
            })
                    .Build()
                    .MigrateDatabase();
        }