static async Task Main(string[] args) { ArgsParser argsParser = new ArgsParser(args); WinService.WinServiceName = "The Sample Service Host"; WinServiceInstaller.WinServiceStatus += new WinServiceInstaller.WinServiceStatusHandler(PrintWinServiceStatus); _logger.Info("Version: " + Assembly.GetEntryAssembly().GetName().Version.ToString()); HostedService service = new HostedService(argsParser); await service.Run(args); _logger.Info("Shutting down logger..."); // Flush buffered log entries before program exit; then shutdown the logger before program exit. LogManager.Flush(TimeSpan.FromSeconds(15)); LogManager.Shutdown(); }
public async Task <int> OnExecuteAsync ( CommandLineApplication app, CancellationToken cancellationToken = default ) { try { _logger.Info("Starting as windows service..."); var builder = HostedService.CreateHostBuilder(); await builder.RunAsWindowsServiceAsync(); } catch (Exception ex) { _logger.Error( "Could not start as windows service. " + ex.Message); app.ShowHelp(); } return(0); }