I have a console application which I want to use to run as Windows Service. When I run the application manually I see the console window and there is an error, so the application is immediately closed. How can I keep my console app window up when error occur?
Here's my code:
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>()
.UseUrls("http://0.0.0.0:5678", "https://0.0.0.0:5678");
}).UseWindowsService();
}
I've tried to add Console.ReadLine();
just after the line but doesn't work as expected. Once after error occurs application is closed.
CreateHostBuilder(args).Build().Run();