public List <SysExceptionModel> GetList(ref GridPager pager, string queryStr) { SysExceptionContext db = new SysExceptionContext(); List <SysExceptionModel> query = null; IQueryable <SysExceptionModel> list = sysException.GetList(db); if (!string.IsNullOrWhiteSpace(queryStr)) { list = list.Where(a => a.Message.Contains(queryStr)); pager.totalRows = list.Count(); } else { pager.totalRows = list.Count(); } if (pager.order == "desc") { query = list.OrderByDescending(c => c.CreateTime).Skip((pager.page - 1) * pager.rows).Take(pager.rows).ToList(); } else { query = list.OrderBy(c => c.CreateTime).Skip((pager.page - 1) * pager.rows).Take(pager.rows).ToList(); } return(query); }
public SysExceptionModel GetById(string id) { using (SysExceptionContext db = new SysExceptionContext()) { return(db.sysExceptions.SingleOrDefault(a => a.Id == id)); } }
public int Create(SysExceptionModel entity) { using (SysExceptionContext db = new SysExceptionContext()) { db.sysExceptions.Add(entity); return(db.SaveChanges()); } }
/// <summary> /// 加入异常日志 /// </summary> /// <param name="ex">异常</param> public static void WriteException(Exception ex) { try { using (SysExceptionContext db = new SysExceptionContext()) { SysExceptionModel model = new SysExceptionModel() { Id = ResultHelper.NewId, HelpLink = ex.HelpLink, Message = ex.Message, Source = ex.Source, StackTrace = ex.StackTrace, TargetSite = ex.TargetSite.ToString(), Assembly = ex.Data.ToString(), CreateTime = ResultHelper.NowTime }; db.sysExceptions.Add(model); db.SaveChanges(); } } catch (Exception ep) { try { //异常失败写入txt string path = @"~/exceptionLog.txt"; string txtPath = System.Web.HttpContext.Current.Server.MapPath(path);//获取绝对路径 using (StreamWriter sw = new StreamWriter(txtPath, true, Encoding.Default)) { sw.WriteLine((ex.Message + "|" + ex.StackTrace + "|" + ep.Message + "|" + DateTime.Now.ToString()).ToString()); sw.Dispose(); sw.Close(); } return; } catch { return; } } }