public IActionResult Add([FromBody] ServiceEventLog eventlog) { if (eventlog == null) { return(BadRequest()); } using (var db = new AllInOneContext.AllInOneContext()) { try { db.ServiceEventLog.Add(eventlog); db.SaveChanges(); //广播消息 publish(eventlog); return(CreatedAtAction("", eventlog)); } catch (DbUpdateException ex) { _logger.LogError("添加服务事件异常,Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); return(BadRequest(new ApplicationException() { ErrorCode = "DbUpdate", ErrorMessage = ex.Message })); } catch (Exception ex) { _logger.LogError("添加服务事件异常,Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); return(BadRequest(new ApplicationException() { ErrorCode = "Unknow", ErrorMessage = ex.Message })); } } }
/// <summary> /// Do some work in this procedure /// </summary> private void DoWork(object state) { if (_workStartTime != DateTime.MinValue) { // probably check how much time has elapsed since work started // and log any warning ServiceEventLog.WriteEntry("Warning! Worker busy since " + _workStartTime.ToLongTimeString() , System.Diagnostics.EventLogEntryType.Warning); } else { // set work start time _workStartTime = DateTime.Now; // Do some work // Note: exception handling is very important here // if you dont, the error will vanish along with your worker thread try { ServiceEventLog.WriteEntry("Timer Service Tick :" + DateTime.Now.ToString()); } catch (System.Exception ex) { // add some robust logging here ServiceEventLog.WriteEntry("Error! " + ex.Message, System.Diagnostics.EventLogEntryType.Error); } // reset work start time _workStartTime = DateTime.MinValue; } }
protected override void OnStart(string[] args) { ServiceEventLog.WriteEntry("Schoology Sync Sevice Starting.", EventLogEntryType.Information); SyncTimer.Start(); AdjustmentTimer.Start(); MailControler.MailToWebmaster("Schoology Sync Service Started.", "Sync Service is Started!"); }
protected override void OnStop() { SyncTimer.Stop(); AdjustmentTimer.Stop(); SyncTimer.Dispose(); AdjustmentTimer.Dispose(); ServiceEventLog.WriteEntry("Schoology Sync Service Is Stopped.", EventLogEntryType.Information); MailControler.MailToWebmaster("Schoology Sync Service Stopped.", "The Schoology Sync Service has been Stopped..."); }
void CourseAndSectonsTimer_Elapsed(object sender, ElapsedEventArgs e) { String Report = ""; ServiceEventLog.WriteEntry("Checking for Changes to Schoology Courses and Sections.", EventLogEntryType.Information); Report += SchoologySync.GetCoursesFromSchoology(); Report += "\n" + SchoologySync.GetSchoologySectionIdsForTerm(DateRange.GetCurrentOrLastTerm()); ServiceEventLog.WriteEntry(Report, EventLogEntryType.SuccessAudit); ServiceEventLog.WriteEntry("Completed Course and Section Sync.", EventLogEntryType.Information); MailControler.MailToWebmaster("Schoology Course and Section Sync.", Report); }
void SyncTimer_Elapsed(object sender, ElapsedEventArgs e) { ServiceEventLog.WriteEntry("Syncing Schoology Attendances.", EventLogEntryType.Information); long ticks = DateTime.Now.Ticks; String report = ""; //this.CanStop = false; try { report = AttendanceControl.PullFromSchoology(); } catch (SchoologyAPICall.SchoologyAPIException apiex) { String Message = apiex.Message; Exception inner = apiex.InnerException; while (inner != null) { Message += Environment.NewLine + "________________________________________" + Environment.NewLine + inner.Message; } ServiceEventLog.WriteEntry(String.Format("API Call failed:{0}{1}", Environment.NewLine, Message), EventLogEntryType.Error); MailControler.MailToWebmaster("Schoology Sync Service Error", String.Format("Schoology Sync Service Failed with the following error:{0}{0}{1}", Environment.NewLine, Message)); } catch (Exception ex) { String Message = ex.Message; while (ex.InnerException != null) { ex = ex.InnerException; Message += Environment.NewLine + "________________________________________" + Environment.NewLine + ex.Message; } MailControler.MailToWebmaster("Schoology Sync Service Error", String.Format("Schoology Sync Service Failed with the following error:{0}{0}{1}", Environment.NewLine, Message)); ServiceEventLog.WriteEntry(String.Format(Message), EventLogEntryType.Error); } //this.CanStop = true; ServiceEventLog.WriteEntry(report, EventLogEntryType.Information); ticks = DateTime.Now.Ticks - ticks; TimeSpan ts = new TimeSpan(ticks); ServiceEventLog.WriteEntry(String.Format("Syncronization Complete. This Sync took {0}.", ts), EventLogEntryType.Information); }
public IActionResult GetById(Guid id) { using (var db = new AllInOneContext.AllInOneContext()) { try { ServiceEventLog serviceEventLog = db.ServiceEventLog.FirstOrDefault(t => t.ServiceEventLogId.Equals(id)); if (serviceEventLog == null || !serviceEventLog.ServiceEventLogId.Equals(id)) { return(NotFound()); } return(new OkObjectResult(serviceEventLog)); } catch (Exception ex) { _logger.LogError("获取服务事件记录{0}异常,Message:{1}\r\n,StackTrace:{2}.", id, ex.Message, ex.StackTrace); return(BadRequest(new ApplicationException() { ErrorCode = "Unknow", ErrorMessage = ex.Message })); } } }
void AdjustmentTimer_Elapsed(object sender, ElapsedEventArgs e) { if ((DateTime.Today.DayOfWeek == DayOfWeek.Saturday || DateTime.Today.DayOfWeek == DayOfWeek.Sunday) && SyncTimer.Enabled) { SyncTimer.Stop(); CourseAndSectonsTimer.Stop(); ServiceEventLog.WriteEntry("Turned off Attendance Sync for the Weekend.", EventLogEntryType.Information); return; } else if (DateTime.Today.DayOfWeek == DayOfWeek.Saturday || DateTime.Today.DayOfWeek == DayOfWeek.Sunday) { return; } switch (DateTime.Now.Hour) { case 6: SyncTimer.Start(); CourseAndSectonsTimer.Start(); ServiceEventLog.WriteEntry("Waking up Sync for the Day."); break; case 8: SyncTimer.Interval = TimeSpan.FromMinutes(10).TotalMilliseconds; ServiceEventLog.WriteEntry("Attendance Sync Interval set to 10 minutes for the Academic Day.", EventLogEntryType.Information); break; case 17: SyncTimer.Interval = TimeSpan.FromHours(1).TotalMilliseconds; ServiceEventLog.WriteEntry("Attendance Sync Interval set to 1 hour for off hours.", EventLogEntryType.Information); break; case 22: SyncTimer.Stop(); CourseAndSectonsTimer.Stop(); ServiceEventLog.WriteEntry("Stopped Sync for the Night.", EventLogEntryType.Information); break; default: break; } }
public IActionResult publish([FromBody] ServiceEventLog eventLog) { MQPulish.PublishMessage("ServiceEventLog", eventLog); return(Ok()); }