HostStatic = CreateHostBuilder(args).Build(); HostStatic.Run(); } public static IHostBuilder CreateHostBuilder(string[] args) { var root = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); Console.WriteLine("Root: " + root); var builder = Host.CreateDefaultBuilder(args) .ConfigureLogging(logging => { logging .ClearProviders() .AddFilter("Microsoft", LogLevel.Error) .AddFilter("System", LogLevel.Error); }) .ConfigureWebHostDefaults(webBuilder => { webBuilder .UseUrls(LocalHost) .UseStartup<Startup>(); }); if (Utilitario.EhLinux()) builder = builder.UseSystemd(); else builder = builder.UseWindowsService(); builder.ConfigureServices((hostContext, services) => { services.AddHostedService<Worker>(); }); return builder; } } public class Worker : BackgroundService { protected override Task ExecuteAsync(CancellationToken stoppingToken) { return Task.Run(() => { }); } public override Task StopAsync(CancellationToken cancellationToken) { return base.StopAsync(cancellationToken); } }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Discussion on: How to Host ASP.NET Core 3.1 Web Applications as Windows Service
For further actions, you may consider blocking this person and/or reporting abuse