private static void NotifyViaMail(Exception ex) { // if a MailException itself, exit to avoid an infinite loop if (ex is MailException || !EnableMailNotifications) { return; } if (mailNotifier == null) { WriteToLog(LogEntryType.Warning, "Email notifications are enabled but not configured. The email could not be sent."); return; } string msg = ""; Integration integration = null; JobInstance jobInstance = null; JobStepInstance jobStepInstance = null; try { // returns null if not found jobInstance = JobQueueManager.GetJobInstanceByParallelTaskId(Thread.CurrentThread.ManagedThreadId); if (jobInstance != null) { integration = jobInstance.Integration; jobStepInstance = jobInstance.RunningJobStepInstance; } var jobInfo = MailFormatter.GetFormattedJobInfoAsHtml(integration, jobInstance, jobStepInstance); msg = MailFormatter.GetTextAsFormattedDiv(jobInfo) + ExceptionFormatter.FormatExceptionForWeb(ex); } catch (Exception innerEx) { StringBuilder failureInfo = new StringBuilder(); failureInfo.AppendFormat("<b>Job info could not be obtained because of error:</b><br /> {0} {1}", innerEx.Message, innerEx.StackTrace); failureInfo.Append(HtmlBuilder.GetLineBreak(2)); msg = MailFormatter.GetTextAsFormattedDiv(failureInfo.ToString()) + ExceptionFormatter.FormatExceptionForWeb(ex); } // Exceptions are caught within MailNotifier class and logged via the SyncEngineLogger if (integration == null) { mailNotifier.SendMessage("SyncObjX Integration Services - An Error Has Occurred", msg); } else { mailNotifier.SendMessage(string.Format("SyncObjX Integration Services - Error Occurred in \"{0}\"", integration.Name), msg); } }
public static void WriteByParallelTaskContext(LogEntryType logEntryType, DataSource dataSource, Func <string> messageDelegate) { Integration integration = null; JobInstance jobInstance = null; JobStepInstance jobStepInstance = null; try { // returns null if not found jobInstance = JobQueueManager.GetJobInstanceByParallelTaskId(Thread.CurrentThread.ManagedThreadId); if (jobInstance != null) { integration = jobInstance.Integration; jobStepInstance = jobInstance.RunningJobStepInstance; } WriteToLog(logEntryType, integration, dataSource, jobInstance, jobStepInstance, messageDelegate); } catch (Exception ex) { WriteExceptionToLog(integration, dataSource, jobInstance, jobStepInstance, ex); } }