private bool Notity(ErrorEntityDto errorMessage) { WebSite webSite = _webSiteBusiness.GetSingleOrDefault(string.Format("select * from WebSite where WebToken='{0}'", errorMessage.WebToken)); if (webSite == null) { LogHelper.Warn("根据webtoken未找到对应的配置,可能为非法请求!"); return(false); } //SendMail(webSite, errorMessage); return(true); }
/// <summary> /// 1. Redis的list可以模拟队列 异常信息都会发送到队列中进行暂存 /// 2. 对于异常信息, 会发送到Redis List中, 但是Redis的List的Value并不支持复杂结构的对象, 所以这里采用类似于2级指针的方法, 将ErrorEntity.Id放入到队列中, ErrorEntity则以普通的方式set到Redis中, 在获取数据的时候,从队列中获取到ErrorEntity.Id , 这样取出来的Id确保顺序不会变, 再根据这个Id, 通过get取出实体。 /// 3. 这种方法其实还有待考虑, 虽然List不支持复杂Value, 但是通过json序列化,我们还是可以直接将ErrorEntity放入到List中 /// </summary> /// <param name="errorEntity"></param> /// <returns></returns> public HttpResponseMessage Post([FromBody] ErrorEntityDto errorEntity) { if (errorEntity != null && !string.IsNullOrWhiteSpace(errorEntity.Id)) { if (RedisHelper.EnqueueItemOnList("ErrorEntityQueue", errorEntity.Id)) //先将ErrorEntity.Id放入到队列中,确保顺序不会变 { if (RedisHelper.Set(errorEntity.Id, errorEntity)) //将实体添加到Redis中 { return(ReturnPlainText("ok")); } return(ReturnPlainText("set error")); } return(ReturnPlainText("add item to list error")); } return(ReturnPlainText("modle error")); }
private void SendMail(WebSite webSite, ErrorEntityDto errorMessage) { string context = ""; if (errorMessage.Type == 0) //普通系统异常 { context = string.Format(EmailTital, webSite.Manager, webSite.WebName, errorMessage.DateTime.ToString("yyyy-MM-dd HH:mm:ss")); context += string.Format(EMailbody, webSite.WebName, errorMessage.MachineName, errorMessage.Ip, errorMessage.RequestUrl, errorMessage.DateTime.ToString("yyyy-MM-dd HH:mm:ss"), errorMessage.ExceptionType, errorMessage.ExceptionMessage, errorMessage.ExceptionSource, errorMessage.ExceptionDetail.Replace("\r\n", "<br/>"), errorMessage.HttpStatusCode, DictionaryHelper.PrintDictionary(errorMessage.ServerVariables).Replace("\r\n", "<br/>"), DictionaryHelper.PrintDictionary(errorMessage.QueryString).Replace("\r\n", "<br/>"), DictionaryHelper.PrintDictionary(errorMessage.Form).Replace("\r\n", "<br/>"), DictionaryHelper.PrintDictionary(errorMessage.Cookies).Replace("\r\n", "<br/>") ); } else //监控异常, 这种异常较为严重,建议发短信 { context = string.Format(EmailTital2, webSite.Manager, webSite.WebName, errorMessage.DateTime.ToString("yyyy-MM-dd HH:mm:ss")); context += string.Format(EMailbody, webSite.WebName, errorMessage.MachineName, errorMessage.Ip, errorMessage.RequestUrl, errorMessage.DateTime.ToString("yyyy-MM-dd HH:mm:ss"), errorMessage.ExceptionType, errorMessage.ExceptionMessage, errorMessage.ExceptionSource, errorMessage.ExceptionDetail.Replace("\r\n", "<br/>"), errorMessage.HttpStatusCode, DictionaryHelper.PrintDictionary(errorMessage.ServerVariables).Replace("\r\n", "<br/>"), DictionaryHelper.PrintDictionary(errorMessage.QueryString).Replace("\r\n", "<br/>"), DictionaryHelper.PrintDictionary(errorMessage.Form).Replace("\r\n", "<br/>"), DictionaryHelper.PrintDictionary(errorMessage.Cookies).Replace("\r\n", "<br/>") ); } MailHelper.SendMail("[异常报警]" + webSite.WebName + "(" + errorMessage.Ip + ")", context, "", new List <string>() { webSite.ManagerEmail }, "", "", ""); }
public void SendSms(WebSite webSite, ErrorEntityDto errorMessage) { //todo 发送短信需要连接短信网关, 这里不再实现 }