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"));
            }
        }
Beispiel #2
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);
        }
Beispiel #3
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);
     }
 }
Beispiel #4
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;
        }
        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"));
            }
        }
        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));
            }
        }
        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"));
            }
        }