static void Main(string[] args) { var exitHandle = new ManualResetEvent(false); var logger = new Log4NetLogger(); var utilServer = new UtilServer(logger, exitHandle); var windowsService = new UtilsWindowsService(utilServer, logger); if (args.Length == 0) { ServiceBase.Run(windowsService); } else switch (args[0]) { case "console": utilServer.Start(); Console.CancelKeyPress += (s, e) => { e.Cancel = true; utilServer.Stop(); }; break; case "install": if (!windowsService.IsInstalled()) windowsService.Install(); break; case "uninstall": if (windowsService.IsInstalled()) windowsService.Uninstall(); break; } }
public UtilsWindowsService(UtilServer server, ISimpleLogger logger) { _server = server; _logger = logger; EventLog.Log = "Application"; ServiceName = "Example Service"; CanStop = true; }