public void Execute(IJobExecutionContext context) { using (_container.BeginLifetimeScope()) { var config = EmailConfiguration.GetConfig(); var loggerFactory = _container.GetInstance <ILoggerFactory>(); ILogger logger = loggerFactory.GetLogger("Scheduler"); var errorFileList = new List <MovedFileOutput>(); try { logger.Info("Scheduler Daily start on " + DateTime.Now); errorFileList.AddRange(_svc.Run(SchedulerEnums.Schedule.DailyOnce)); foreach (var errorFile in errorFileList) { logger.Warn(String.Format("Error on files : {0}", errorFile.FileName)); var body = String.Format("Error on files : {0}", errorFile.FileName); foreach (var error in errorFile.ErrorList) { logger.Info(String.Format(error)); body += String.Format("<p>{0}</p>", error); } logger.Error(EmailUtility.Email(body, null)); } logger.Info("Scheduler Daily ended On " + DateTime.Now); } catch (Exception ex) { logger.Error("Daily scheduler crashed", ex); var body = String.Format("<p>{0}</p>", ex.Message); body += String.Format("<p>{0}</p>", ex.StackTrace); if (!String.IsNullOrEmpty(body)) { logger.Error(EmailUtility.Email(body, "Scheduler is down")); } } //if (errorList.Count > 0) //{ // foreach (var err in errorList) // { // logger.Info(err); // } //} if (errorFileList.Count == 0) { var body = string.Empty; if (_svc.filesMoved.Count > 0) { foreach (var file in _svc.filesMoved) { string info = String.Format("<p>XML file {0} : {1}</p>" , file.IsError ? "Error" : "Archieved" , file.FileName); if (file.IsError) { body += info; } logger.Info(info); } if (!String.IsNullOrEmpty(body)) { logger.Error(EmailUtility.Email(body)); } } } } }