public void Main(string[] args) { // Allow the location of the ini file to be specified via a --config command line arg var tempBuilder = new ConfigurationBuilder().AddCommandLine(args); var tempConfig = tempBuilder.Build(); var configFilePath = tempConfig[ConfigFileKey] ?? HostingIniFile; var appBasePath = _serviceProvider.GetRequiredService<IApplicationEnvironment>().ApplicationBasePath; var builder = new ConfigurationBuilder(appBasePath); builder.AddIniFile(configFilePath, optional: true); builder.AddEnvironmentVariables(); builder.AddCommandLine(args); var config = builder.Build(); var host = new WebHostBuilder(_serviceProvider, config).Build(); using (host.Start()) { Console.WriteLine("Started"); var appShutdownService = host.ApplicationServices.GetRequiredService<IApplicationShutdown>(); Console.CancelKeyPress += (sender, eventArgs) => { appShutdownService.RequestShutdown(); // Don't terminate the process immediately, wait for the Main thread to exit gracefully. eventArgs.Cancel = true; }; appShutdownService.ShutdownRequested.WaitHandle.WaitOne(); } }