private void _stmp_SendCompleted(object sender, AsyncCompletedEventArgs e)
        {
            string    sendState = string.Empty;
            Exception ex        = null;
            DateTime  dateStart = DateTime.Now;

            if (e.Cancelled)
            {
                var dateEnd = DateTime.Now;
                sendState = "异步发送邮件取消";
                CustomerLogUtil.Info(CustomerLogFormatUtil.LogMailMsgfFormat(SmtpClientConfigurationInfo.UserName, string.Join(",", mailMessageInfo.ToMailAddressList), string.Join(",", mailMessageInfo.CCMailAddressList), mailMessageInfo.Subject, mailMessageInfo.Body, sendState), new CustomerLogParameters(Guid.NewGuid().ToString("N"), "SendMail", mailMessageInfo.Body, sendState, dateStart.ToString("yyyy-MM-dd HH:mm:ss.ffff"), dateEnd.ToString("yyyy-MM-dd HH:mm:ss.ffff"), $"{((dateEnd.Ticks - dateStart.Ticks) / 10000)}ms"));
            }
            else if (e.Error != null)
            {
                var dateEnd = DateTime.Now;
                sendState = "异步发送邮件失败";
                ex        = e.Error;
                CustomerLogUtil.Error(ex, CustomerLogFormatUtil.LogMailMsgfFormat(SmtpClientConfigurationInfo.UserName, string.Join(",", mailMessageInfo.ToMailAddressList), string.Join(",", mailMessageInfo.CCMailAddressList), mailMessageInfo.Subject, mailMessageInfo.Body, sendState), new CustomerLogParameters(Guid.NewGuid().ToString("N"), "SendMail", mailMessageInfo.Body, sendState, dateStart.ToString("yyyy-MM-dd HH:mm:ss.ffff"), dateEnd.ToString("yyyy-MM-dd HH:mm:ss.ffff"), $"{((dateEnd.Ticks - dateStart.Ticks) / 10000)}ms"));
            }
            else
            {
                var dateEnd = DateTime.Now;
                sendState = "异步发送邮件成功";
                CustomerLogUtil.Info(CustomerLogFormatUtil.LogMailMsgfFormat(SmtpClientConfigurationInfo.UserName, string.Join(",", mailMessageInfo.ToMailAddressList), string.Join(",", mailMessageInfo.CCMailAddressList), mailMessageInfo.Subject, mailMessageInfo.Body, sendState), new CustomerLogParameters(Guid.NewGuid().ToString("N"), "SendMail", mailMessageInfo.Body, sendState, dateStart.ToString("yyyy-MM-dd HH:mm:ss.ffff"), dateEnd.ToString("yyyy-MM-dd HH:mm:ss.ffff"), $"{((dateEnd.Ticks - dateStart.Ticks) / 10000)}ms"));
            }
        }
Esempio n. 2
0
        //const string log4netInfoKey = "logWebInfo";
        //const string log4netErrorKey = "logWebError";
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var uniqueID = Guid.NewGuid().ToString("N");
            var requestMethodParameters = _getRequestMethodParameters(filterContext);

            CustomerLogUtil.Info(Log4NetKeys.Log4netWebInfoKey, CustomerLogFormatUtil.LogWebMsgFormat(uniqueID, filterContext.HttpContext.Request.Url.ToString(), requestMethodParameters["httpMethod"], requestMethodParameters["requestParams"]));
            filterContext.Controller.ViewData["ID"] = uniqueID;
        }
Esempio n. 3
0
        private void _logError(Exception exception, ExceptionContext filterContext)
        {
            var uniqueID = filterContext.Controller.ViewData["ID"] as string;
            var url      = filterContext.RequestContext.HttpContext.Request.Url.ToString();
            var requestMethodParameters = _getRequestMethodParameters(filterContext);

            filterContext.ExceptionHandled = true;
            filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
            CustomerLogUtil.Error(Log4NetKeys.Log4netWebErrorKey, CustomerLogFormatUtil.LogWebMsgFormat(uniqueID, url, requestMethodParameters["httpMethod"], requestMethodParameters["requestParams"]), exception);
        }
Esempio n. 4
0
 public override void OnActionExecuted(ActionExecutedContext filterContext)
 {
     if (filterContext.Result is JsonResult)
     {
         var uniqueID   = filterContext.Controller.ViewData["ID"] as string;
         var jsonResult = filterContext.Result as JsonResult;
         CustomerLogUtil.Info(Log4NetKeys.Log4netWebInfoKey, CustomerLogFormatUtil.LogWebMsgFormat(uniqueID, filterContext.HttpContext.Request.Url.ToString(), filterContext.HttpContext.Request.HttpMethod, reponseData: JsonConvert.SerializeObject(jsonResult.Data)));
     }
     base.OnActionExecuted(filterContext);
 }
Esempio n. 5
0
 public override void Post(JobExcutedCallBackModel jobExcutedCallBackModel)
 {
     try
     {
         CustomerLogUtil.Info(jobExcutedCallBackModel.Log4NetKey_JobInfo, CustomerLogFormatUtil.LogJobMsgFormat(jobExcutedCallBackModel.JobName, jobExcutedCallBackModel.JobState, jobExcutedCallBackModel.OperateType));
         var _httpClient = new HttpClientHelper();
         var result      = _httpClient.PostAsync(jobExcutedCallBackModel.RequestBody, jobExcutedCallBackModel.RequestUrl).Result;
     }
     catch (Exception ex)
     {
         CustomerLogUtil.Error(jobExcutedCallBackModel.Log4NetKey_JobError, CustomerLogFormatUtil.LogJobMsgFormat(jobExcutedCallBackModel.JobName, jobExcutedCallBackModel.JobState, jobExcutedCallBackModel.OperateType), ex);
     }
 }
        public override void SendMail(SchedulerExecutedCallBackModel schedulerExecutedCallBackModel)
        {
            var dateStart  = DateTime.Now;
            var mailClient = new MailClient();

            mailClient.SendMail(new MailMessageConfigurationInfo {
                Body = CustomerLogFormatUtil.LogSchedulerMsgFormat(SchedulerExecutedCallBackModel.LocalIP, SchedulerExecutedCallBackModel.QuartzServerName, schedulerExecutedCallBackModel.OperateType, schedulerExecutedCallBackModel.OperateState), Subject = schedulerExecutedCallBackModel.Subject, ToMailAddressList = schedulerExecutedCallBackModel.ToMailAddressList
            });
            var dateEnd = DateTime.Now;
            var message = CustomerLogFormatUtil.LogSchedulerMsgFormat(SchedulerExecutedCallBackModel.LocalIP, SchedulerExecutedCallBackModel.QuartzServerName, schedulerExecutedCallBackModel.OperateType, schedulerExecutedCallBackModel.OperateState);

            CustomerLogUtil.Info(message, new CustomerLogParameters(schedulerExecutedCallBackModel.GuId, "SendMail", message, "", dateStart.ToString("yyyy-MM-dd HH:mm:ss.ffff"), dateEnd.ToString("yyyy-MM-dd HH:mm:ss.ffff"), $"{((dateEnd.Ticks - dateStart.Ticks) / 10000)}ms"));
        }
        public void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
        {
            var jobName     = context.JobDetail.Key.Name;
            var jobState    = 6;
            var operateType = "运行";

            string exceptionMessage = jobException == null ? null : jobException.Message;


            this.NotifyAsync(new JobExcutedCallBackModel {
                IsJobDeleted = false, JobName = jobName, JobState = jobState, Log4NetKey_JobError = Log4NetKeys.Log4netJobErrorKey, Log4NetKey_JobInfo = Log4NetKeys.Log4netJobInfoKey, OperateType = operateType, RequestUrl = "", RequestBody = new { JobName = jobName, JobState = jobState, Exception = exceptionMessage, PreTime = context.Trigger.GetPreviousFireTimeUtc().HasValue ? context.Trigger.GetPreviousFireTimeUtc().Value.LocalDateTime as DateTime? : null, NextTime = context.Trigger.GetNextFireTimeUtc().HasValue ? context.Trigger.GetNextFireTimeUtc().Value.LocalDateTime as DateTime? : null }
            });
            CustomerLogUtil.Info(Log4NetKeys.Log4netJobInfoKey, CustomerLogFormatUtil.LogJobMsgFormat(jobName, jobState, operateType));
        }
Esempio n. 8
0
        public void OnException(ExceptionContext context)
        {
            if (context.ExceptionHandled)
            {
                return;
            }
            var requestEndTime        = DateTime.Now;
            var exception             = context.Exception;
            var requestStartTime      = context.HttpContext.Request.Headers["RequestStartTime"];
            var requestStartTimeTicks = Convert.ToInt64(context.HttpContext.Request.Headers["RequestStartTimeTicks"]);
            var url_Method_Parameters = _getRequestMethodAndParameters(context);

            CustomerLogUtil.Error(exception, $"Action请求发生异常#{url_Method_Parameters.Item1}", new CustomerLogParameters(context.HttpContext.Request.Headers["UniqueId"], url_Method_Parameters.Item2, url_Method_Parameters.Item3, "", requestStartTime, requestEndTime.ToString("yyyy-MM-dd HH:mm:ss.ffff"), $"{((requestEndTime.Ticks - requestStartTimeTicks) / 10000)}ms"));
            context.ExceptionHandled = true;
        }
Esempio n. 9
0
        public void SendMail(MailMessageConfigurationInfo mailMessageConfigurationInfo)
        {
            try
            {
                mailMessageInfo = mailMessageConfigurationInfo;
                var smtpClient  = _configureSmtpClient();
                var mailMessage = _configureMailMessage();

                smtpClient.SendCompleted += new SendCompletedEventHandler(_stmp_SendCompleted);
                smtpClient.SendAsync(mailMessage, "ok");
            }
            catch (Exception ex)
            {
                sendState = "异步发送邮件失败";
                CustomerLogUtil.Error(Log4NetKeys.Log4netMailErrorKey, CustomerLogFormatUtil.LogMailMsgfFormat(SmtpClientConfigurationInfo.UserName, string.Join(",", mailMessageInfo.ToMailAddressList), string.Join(",", mailMessageInfo.CCMailAddressList), mailMessageInfo.Subject, mailMessageInfo.Body, sendState), ex);
            }
        }
        public override void Post(JobExcutedCallBackModel jobExcutedCallBackModel)
        {
            var dateStart = DateTime.Now;

            try
            {
                var _httpClient = new HttpClientHelper();
                var result      = _httpClient.PostAsync(jobExcutedCallBackModel.RequestBody, jobExcutedCallBackModel.RequestUrl).Result;
                var dateEnd     = DateTime.Now;
                CustomerLogUtil.Info(CustomerLogFormatUtil.LogJobMsgFormat(jobExcutedCallBackModel.JobName, jobExcutedCallBackModel.JobState, jobExcutedCallBackModel.OperateType), new CustomerLogParameters(jobExcutedCallBackModel.GuId, "POST", Newtonsoft.Json.JsonConvert.SerializeObject(jobExcutedCallBackModel.RequestBody), result, dateStart.ToString("yyyy-MM-dd HH:mm:ss.ffff"), dateEnd.ToString("yyyy-MM-dd HH:mm:ss.ffff"), $"{((dateEnd.Ticks - dateStart.Ticks) / 10000)}ms"));
            }
            catch (Exception ex)
            {
                var dateEnd = DateTime.Now;
                CustomerLogUtil.Error(ex, CustomerLogFormatUtil.LogJobMsgFormat(jobExcutedCallBackModel.JobName, jobExcutedCallBackModel.JobState, jobExcutedCallBackModel.OperateType), new CustomerLogParameters(jobExcutedCallBackModel.GuId, "POST", Newtonsoft.Json.JsonConvert.SerializeObject(jobExcutedCallBackModel.RequestBody), "", dateStart.ToString("yyyy-MM-dd HH:mm:ss.ffff"), dateEnd.ToString("yyyy-MM-dd HH:mm:ss.ffff"), $"{((dateEnd.Ticks - dateStart.Ticks) / 10000)}ms"));
            }
        }
Esempio n. 11
0
        public void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
        {
            var jobName     = context.JobDetail.Key.Name;
            var jobState    = 6;
            var operateType = "运行";

            string exceptionMessage = jobException == null ? null : jobException.Message;

            #region RecodJobExecutedInfo

            //AddJob
            var jobNameTime      = jobName + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss");
            var jobGroupName     = context.JobDetail.Key.Group;
            var triggerName      = context.Trigger.Key.Name;
            var triggerGroupName = context.Trigger.Key.Group;

            var cron           = "1";
            var jobDescription = jobName + DateTime.Now;
            var requestUrl     = "1";
            var cycle          = "1";
            var repeatCount    = "1";
            var triggerType    = "";

            this.NotifyAsync(new JobExcutedCallBackModel {
                IsJobDeleted = false, JobName = jobNameTime, JobState = 2, Log4NetKey_JobError = Log4NetKeys.Log4netJobErrorKey, Log4NetKey_JobInfo = Log4NetKeys.Log4netJobInfoKey, OperateType = operateType, RequestUrl = "http://localhost:52044/JobManager/AddJob", RequestBody = new { TriggerState = 2, JobName = jobNameTime, JobGroupName = jobGroupName, TriggerName = triggerName, TriggerGroupName = triggerGroupName, CronJob = new { Cron = cron }, JobDescription = jobDescription, RequestUrl = requestUrl, SimpleJob = new { Cycle = cycle, RepeatCount = repeatCount }, TriggerType = triggerType, JobState = jobState, Exception = exceptionMessage, PreTime = context.Trigger.GetPreviousFireTimeUtc().HasValue ? context.Trigger.GetPreviousFireTimeUtc().Value.LocalDateTime as DateTime? : null, NextTime = context.Trigger.GetNextFireTimeUtc().HasValue ? context.Trigger.GetNextFireTimeUtc().Value.LocalDateTime as DateTime? : null }
            });

            this.NotifyAsync(new JobExcutedCallBackModel {
                IsJobDeleted = false, JobName = jobNameTime, JobState = jobState, Log4NetKey_JobError = Log4NetKeys.Log4netJobErrorKey, Log4NetKey_JobInfo = Log4NetKeys.Log4netJobInfoKey, OperateType = operateType, RequestUrl = "http://localhost:52044/JobManager/UpdateJobInfo", RequestBody = new { JobName = jobNameTime, JobState = 2, Exception = exceptionMessage, PreTime = context.Trigger.GetPreviousFireTimeUtc().HasValue ? context.Trigger.GetPreviousFireTimeUtc().Value.LocalDateTime as DateTime? : null, NextTime = context.Trigger.GetNextFireTimeUtc().HasValue ? context.Trigger.GetNextFireTimeUtc().Value.LocalDateTime as DateTime? : null }
            });
            #endregion

            //UpdateJobInfo
            this.NotifyAsync(new JobExcutedCallBackModel {
                IsJobDeleted = false, JobName = jobName, JobState = jobState, Log4NetKey_JobError = Log4NetKeys.Log4netJobErrorKey, Log4NetKey_JobInfo = Log4NetKeys.Log4netJobInfoKey, OperateType = operateType, RequestUrl = "http://localhost:52044/JobManager/UpdateJobInfo", RequestBody = new { JobName = jobName, JobState = jobState, Exception = exceptionMessage, PreTime = context.Trigger.GetPreviousFireTimeUtc().HasValue ? context.Trigger.GetPreviousFireTimeUtc().Value.LocalDateTime as DateTime? : null, NextTime = context.Trigger.GetNextFireTimeUtc().HasValue ? context.Trigger.GetNextFireTimeUtc().Value.LocalDateTime as DateTime? : null }
            });



            CustomerLogUtil.Info(Log4NetKeys.Log4netJobInfoKey, CustomerLogFormatUtil.LogJobMsgFormat(jobName, jobState, operateType));
        }
Esempio n. 12
0
        public override void OnActionExecuted(ActionExecutedContext context)
        {
            var requestEndTime        = DateTime.Now;
            var requestStartTime      = context.HttpContext.Request.Headers["RequestStartTime"];
            var requestStartTimeTicks = Convert.ToInt64(context.HttpContext.Request.Headers["RequestStartTimeTicks"]);
            var uniqueId = context.HttpContext.Request.Headers["UniqueId"];
            var url_Method_Parameters = _getRequestMethodAndParameters(context);
            var result = context.Result as JsonResult;

            if (result != null)
            {
                CustomerLogUtil.Info($"Action请求#{url_Method_Parameters.Item1}", new CustomerLogParameters(uniqueId, url_Method_Parameters.Item2, url_Method_Parameters.Item3, JsonConvert.SerializeObject(result.Value), requestStartTime, requestEndTime.ToString("yyyy-MM-dd HH:mm:ss.ffff"), $"{((requestEndTime.Ticks - requestStartTimeTicks) / 10000)}ms"));
            }
            else
            {
                CustomerLogUtil.Info($"Action请求#{url_Method_Parameters.Item1}", new CustomerLogParameters(uniqueId, url_Method_Parameters.Item2, url_Method_Parameters.Item3, "", requestStartTime, requestEndTime.ToString("yyyy-MM-dd HH:mm:ss.ffff"), $"{((requestEndTime.Ticks - requestStartTimeTicks) / 10000)}ms"));
            }


            base.OnActionExecuted(context);
        }
Esempio n. 13
0
        private void _stmp_SendCompleted(object sender, AsyncCompletedEventArgs e)
        {
            string    sendState = string.Empty;
            Exception ex        = null;

            if (e.Cancelled)
            {
                sendState = "异步发送邮件取消";
                CustomerLogUtil.Error(Log4NetKeys.Log4netMailErrorKey, CustomerLogFormatUtil.LogMailMsgfFormat(SmtpClientConfigurationInfo.UserName, string.Join(",", mailMessageInfo.ToMailAddressList), string.Join(",", mailMessageInfo.CCMailAddressList), mailMessageInfo.Subject, mailMessageInfo.Body, sendState));
            }
            else if (e.Error != null)
            {
                sendState = "异步发送邮件失败";
                ex        = e.Error;
                CustomerLogUtil.Error(Log4NetKeys.Log4netMailErrorKey, CustomerLogFormatUtil.LogMailMsgfFormat(SmtpClientConfigurationInfo.UserName, string.Join(",", mailMessageInfo.ToMailAddressList), string.Join(",", mailMessageInfo.CCMailAddressList), mailMessageInfo.Subject, mailMessageInfo.Body, sendState), e.Error);
            }
            else
            {
                sendState = "异步发送邮件成功";
                CustomerLogUtil.Info(Log4NetKeys.Log4netMailInfoKey, CustomerLogFormatUtil.LogMailMsgfFormat(SmtpClientConfigurationInfo.UserName, string.Join(",", mailMessageInfo.ToMailAddressList), string.Join(",", mailMessageInfo.CCMailAddressList), mailMessageInfo.Subject, mailMessageInfo.Body, sendState));
            }
        }
Esempio n. 14
0
        public void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
        {
            var jobName     = context.JobDetail.Key.Name;
            var jobState    = 6;
            var operateType = "运行";
            //try
            //{
            //    HttpClientHelper httpClient = new HttpClientHelper();
            string exceptionMessage = jobException == null ? null : jobException.Message;

            //var reuslt = httpClient.PostAsync(new { JobName = jobName, JobState = jobState, Exception = exceptionMessage, PreTime = context.Trigger.GetPreviousFireTimeUtc().HasValue ? context.Trigger.GetPreviousFireTimeUtc().Value.LocalDateTime as DateTime? : null, NextTime = context.Trigger.GetNextFireTimeUtc().HasValue ? context.Trigger.GetNextFireTimeUtc().Value.LocalDateTime as DateTime? : null }).Result;
            this.NotifyAsync(new JobExcutedCallBackModel {
                IsJobDeleted = false, JobName = jobName, JobState = jobState, Log4NetKey_JobError = Log4NetKeys.Log4netJobErrorKey, Log4NetKey_JobInfo = Log4NetKeys.Log4netJobInfoKey, OperateType = operateType, RequestUrl = "", RequestBody = new { JobName = jobName, JobState = jobState, Exception = exceptionMessage, PreTime = context.Trigger.GetPreviousFireTimeUtc().HasValue ? context.Trigger.GetPreviousFireTimeUtc().Value.LocalDateTime as DateTime? : null, NextTime = context.Trigger.GetNextFireTimeUtc().HasValue ? context.Trigger.GetNextFireTimeUtc().Value.LocalDateTime as DateTime? : null }
            });
            CustomerLogUtil.Info(Log4NetKeys.Log4netJobInfoKey, CustomerLogFormatUtil.LogJobMsgFormat(jobName, jobState, operateType));
            //}
            //catch (Exception ex)
            //{

            //    CustomerLog.Error(log4netErrorKey,CustomerLogFormatUtil.LogJobMsgFormat(jobName, jobState, operateType), ex);
            //}
        }
        public void SendMail(MailMessageConfigurationInfo mailMessageConfigurationInfo)
        {
            DateTime dateStart = DateTime.Now;

            try
            {
                mailMessageInfo = mailMessageConfigurationInfo;
                var smtpClient  = _configureSmtpClient();
                var mailMessage = _configureMailMessage();

                smtpClient.SendCompleted += new SendCompletedEventHandler(_stmp_SendCompleted);
                dateStart = DateTime.Now;
                smtpClient.SendAsync(mailMessage, "ok");
            }
            catch (Exception ex)
            {
                var dateEnd = DateTime.Now;
                sendState = "异步发送邮件失败";

                CustomerLogUtil.Error(ex, CustomerLogFormatUtil.LogMailMsgfFormat(SmtpClientConfigurationInfo.UserName, string.Join(",", mailMessageInfo.ToMailAddressList), string.Join(",", mailMessageInfo.CCMailAddressList), mailMessageInfo.Subject, mailMessageInfo.Body, sendState), new CustomerLogParameters(Guid.NewGuid().ToString("N"), "SendMail", mailMessageInfo.Body, sendState, dateStart.ToString("yyyy-MM-dd HH:mm:ss.ffff"), dateEnd.ToString("yyyy-MM-dd HH:mm:ss.ffff"), $"{((dateEnd.Ticks - dateStart.Ticks) / 10000)}ms"));
            }
        }