Exemplo n.º 1
0
 /// <summary>
 /// 发送日志到邮件
 /// </summary>
 /// <param name="log"></param>
 private void SendEmail(CommonLog log)
 {
     var mail = ExceptionEmailConfigs.ConfigEntity;
     var smtp = new SmtpMail(mail.LoginName, mail.LoginPwd, mail.SendMail, $"Farseer.Net {EnumNameCacheManger.Cache(_logType)}记录", mail.SmtpServer, 0, mail.SmtpPort);
     var body = new StringBuilder();
     body.AppendFormat($"<b>发现时间:</b> {log.CreateAt:yyyy年MM月dd日 HH:mm:ss}<br />");
     body.AppendFormat($"<b>程序文件:</b> <u>{log.FileName}</u> <b>第{log.LineNo}行</b> <font color=red>{log.MethodName}()</font><br />");
     body.AppendFormat($"<b>日志消息:</b><font color=red>{0}</font><br />", log.Message);
     smtp.Send(mail.EmailAddress, $"{DateTime.Now:yyyy年MM月dd日 HH:mm:ss}:{EnumNameCacheManger.Cache(_logType)}消息:{log.Message}", body.ToString());
 }
Exemplo n.º 2
0
 /// <summary>
 /// 添加日志消息
 /// </summary>
 /// <param name="message">消息内容</param>
 /// <param name="exp">异常</param>
 public void Write(string message, Exception exp) 
 {
     var log = new CommonLog { Exp = exp, Message = message ?? exp.Message.Replace("\r\n", "") };
     log.RecordExecuteMethod();
     //写入日志
     Add(log);
     // 发送邮件
     if (_logType == EumLogType.Error && SystemConfigs.ConfigEntity.IsSendErrorEmail) { SendEmail(log); }
 }