using log4net; using Quartz; using Quartz.Impl; using System; using System.Collections.Generic; using System.Linq; using System.ServiceProcess; using System.Text; namespace JobScheduler { static class Program { /// /// 应用程序的主入口点。 /// static void Main() { #region 正式入口 //ServiceBase[] ServicesToRun; //ServicesToRun = new ServiceBase[] //{ // new JobService() //}; //ServiceBase.Run(ServicesToRun); #endregion #region 测试用入口 try { IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler(); scheduler.ListenerManager.AddSchedulerListener(new SchedulerListener()); scheduler.Start(); } catch (Exception e) { ILog log = LogManager.GetLogger(typeof(SchedulerListener)); log.Debug($"error:{e.Message}"); } #endregion } class SchedulerListener : ISchedulerListener { ILog log = LogManager.GetLogger(typeof(SchedulerListener)); public void JobAdded(IJobDetail jobDetail) { log.Debug($"JobAdded:{jobDetail.Key}"); } public void JobDeleted(JobKey jobKey) { log.Debug($"JobDeleted:{jobKey}"); } public void JobPaused(JobKey jobKey) { log.Debug($"JobPaused:{jobKey}"); } public void JobResumed(JobKey jobKey) { log.Debug($"JobResumed:{jobKey}"); } public void JobScheduled(ITrigger trigger) { } public void JobsPaused(string jobGroup) { } public void JobsResumed(string jobGroup) { } public void JobUnscheduled(TriggerKey triggerKey) { } public void SchedulerError(string msg, SchedulerException cause) { log.Error($"SchedulerError:{msg}"); log.Error($"{cause.Message}"); log.Error($"{cause.StackTrace}"); if (cause.InnerException != null) { log.Error(cause.InnerException.Message); log.Error(cause.InnerException.StackTrace); } } public void SchedulerInStandbyMode() { } public void SchedulerShutdown() { } public void SchedulerShuttingdown() { } public void SchedulerStarted() { log.Debug($"启动"); } public void SchedulerStarting() { } public void SchedulingDataCleared() { } public void TriggerFinalized(ITrigger trigger) { log.Debug($"TriggerFinalized:{trigger.Key}"); } public void TriggerPaused(TriggerKey triggerKey) { log.Debug($"TriggerPaused:{triggerKey}"); } public void TriggerResumed(TriggerKey triggerKey) { log.Debug($"TriggerResumed:{triggerKey}"); } public void TriggersPaused(string triggerGroup) { } public void TriggersResumed(string triggerGroup) { } } } }