static void Main(string[] args) { Console.CancelKeyPress += (sender, eArgs) => { _quitEvent.Set(); eArgs.Cancel = true; }; try { Console.WriteLine(String.Format(@"Identified OS version is {0}.", Environment.OSVersion.VersionString)); Init(); Console.WriteLine(@"Finished loading configuration."); WindowsEventLogListener listener = new WindowsEventLogListener(logName, kerberosEventsHandler); Console.WriteLine(@"Listenning to events ..."); } catch (SecurityException) { logger.Log(LogLevels.Error, String.Format(@"Permission denied when trying to access the '{0}' log.", logName)); Environment.Exit(1); } catch (Exception e) { logger.Log(LogLevels.Error, String.Format("Something bad hapenned, do something about it!\nException details:\n{0}", e.Message)); Environment.Exit(1); } _quitEvent.WaitOne(); Environment.Exit(0); }
protected override void OnStart(string[] args) { try { logger.Log(LogLevels.Information, String.Format(@"Identified current OS version as {0}.", Environment.OSVersion.VersionString)); Init(); logger.Log(LogLevels.Information, @"Finished loading configuration."); WindowsEventLogListener logonEventsListener = new WindowsEventLogListener("Security", logonEventsHandler); WindowsEventLogListener kerberosEventsListener = new WindowsEventLogListener("Security", kerberosEventsHandler); logger.Log(LogLevels.Information, @"Started to listen for events ..."); } catch (SecurityException) { logger.Log(LogLevels.Error, @"Permission denied when trying to access the Security log."); Environment.Exit(1); } catch (Exception e) { logger.Log(LogLevels.Error, String.Format("Something bad hapenned, do something about it!\nException details:\n{0}", e.Message)); Environment.Exit(1); } }