public static LogEventArgs GetLogEventArgs(LogTitle logTitle, string content, LogLevel logLevel, Exception exception = null) { return(new LogEventArgs() { LogTitle = logTitle, Content = content, LogLevel = logLevel, Exception = exception }); }
/// <summary> /// 记录普通日志到数据库 /// </summary> /// <param name="title"></param> /// <param name="log"></param> /// <param name="flag"></param> /// <returns></returns> public BllResult <int?> LogContent(LogTitle logTitle, string log, string userCode, LogLevel flag) { ContentLog contentLog = new ContentLog(); contentLog.Title = logTitle.ToString(); contentLog.Content = log; contentLog.Flag = flag.ToString(); contentLog.Created = DateTime.Now; contentLog.CreatedBy = userCode.ToString(); return(AppSession.Dal.InsertCommonModel <ContentLog>(contentLog)); }
/// <summary> /// 自定义日志文件名称的日志记录函数 title开头 /// </summary> /// <param name="title"></param> /// <param name="Message"></param> public void WriteLog(string title, string Message, LogTitle logTitle = LogTitle.设备调度日志) { if (String.IsNullOrEmpty(Message)) { addLog(title, ""); } else { addLog(title, System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff") + " " + Message); } }
public static void Log(LogTitle logTitle, string content, LogLevel logLevel, Exception exception = null) { //如果这条记录5秒之内插入过,就不再插入 if (contentList.Exists(t => DateTime.Now.Subtract(t.x).TotalSeconds < 9 && t.y == content)) { return; } if (contentList.Count > 50) { contentList.RemoveAt(0); } contentList.Add(new Generics <DateTime, string>(DateTime.Now, content)); LogWrite?.Invoke(null, LogEventArgs.GetLogEventArgs(logTitle, content, logLevel, exception)); }
/// <summary> /// 自定义文件名称的数据操作异常信息跟踪 title /// </summary> /// <param name="tile"></param> /// <param name="ex"></param> public void WriteExceptionLog(string tile, Exception ex, LogTitle logTitle = LogTitle.设备调度日志) { try { if (ex != null && ex.Message != "ExceptionTag") { StringBuilder sb = new StringBuilder(); string NowDateTime = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff"); sb.AppendLine(string.Format("****************************{0},Exception[{1}]****************************", NowDateTime, tile)); sb.AppendLine(ex.ToString()); sb.AppendLine(ex.Message.ToString()); sb.AppendLine(ex.TargetSite.ToString()); sb.AppendLine(ex.StackTrace.ToString()); addLog("Exception", sb.ToString()); } } catch { } }
public static void Log(LogTitle logTitle, string content, LogLevel logLevel, Exception exception = null) { LogWrite?.Invoke(null, LogEventArgs.GetLogEventArgs(logTitle, content, logLevel, exception)); }
///// <summary> ///// 信息跟踪 Info 记录形式为: 时间+信息 ///// </summary> ///// <param name="Message"></param> ///// <param name="IsSucc"></param> //public void WriteInfoLog(string Message, bool IsSucc) //{ // string s = IsSucc ? "成功" : "失败"; // WriteInfoLog(Message + ",操作结果[" + s + "]"); //} /// <summary> /// 数据库操作异常信息跟踪 DBExecute /// </summary> /// <param name="ex"></param> public void WriteDBExceptionLog(Exception ex, LogTitle logTitle = LogTitle.设备调度日志) { WriteExceptionLog("DBExecute", ex, logTitle); }
public object Clone() { return(new Log((string)SoftwareName.Clone(), (string)LogTitle.Clone(), (string)LogDescription.Clone(), (DateLog)Date, (LogType)Type, backColor, foreColor)); }