protected override void OnStart(string[] args) { var logger = NLogHelper.GetFileLogger(LogNames.ServiceLog); logger.Info("TimingService Start"); timingLogger = NLogHelper.GetFileLogger(LogNames.TimingLog); // Create a timer with a two second interval. timer = new System.Timers.Timer(60000); // Hook up the Elapsed event for the timer. timer.Elapsed += OnTimedEvent; timer.AutoReset = true; timer.Enabled = true; }
private static void CurrentDomain_UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { var str = ""; var error = e.Exception; var strDateInfo = "出现应用程序未处理的异常:" + DateTime.Now + "\r\n"; if (error != null) { str = string.Format(strDateInfo + "Application UnhandledException:{0};\n\r堆栈信息:{1}", error.Message, error.StackTrace); var logger = NLogHelper.GetFileLogger("Exception"); logger.Error(str); } else { str = string.Format("Application UnhandledError:{0}", e); var logger = NLogHelper.GetFileLogger("Exception"); logger.Error(str); } MessageBox.Show("很抱歉,当前程序遇到一些问题,该操作已终止,请检查网络连接,如果问题依然存在,请联系管理员", "意外的操作", MessageBoxButton.OK, MessageBoxImage.Information); e.Handled = true; }
protected override void OnStop() { var logger = NLogHelper.GetFileLogger(LogNames.ServiceLog); logger.Info("TimingService Stop"); }