private static void ExportLog(ELogType LogType, string Message) { switch (LogType) { case ELogType.Fatal: LogManager.GetLogger(LogType.ToString()).Fatal(Message); break; case ELogType.Error: LogManager.GetLogger(LogType.ToString()).Error(Message); break; case ELogType.Warn: LogManager.GetLogger(LogType.ToString()).Warn(Message); break; case ELogType.Debug: LogManager.GetLogger(LogType.ToString()).Debug(Message); break; case ELogType.Info: LogManager.GetLogger(LogType.ToString()).Info(Message); break; default: LogManager.GetLogger(typeof(Logging)).Debug(Message); break; } }
public void Log(ELogType t, string format, params object[] args) { string strData = string.Format(format, args); string strAppend = string.Format("[{0}] {1}", t.ToString(), strData + Environment.NewLine); int oldLen = LogRichTextBox.Text.Length; LogRichTextBox.AppendText(strAppend); LogRichTextBox.Select(oldLen, strAppend.Length); switch (t) { case ELogType.INFO: case ELogType.DEBUG: LogRichTextBox.SelectionColor = Color.Black; break; case ELogType.ERROR: case ELogType.FATAL: LogRichTextBox.SelectionColor = Color.Red; break; case ELogType.WARN: LogRichTextBox.SelectionColor = Color.Blue; break; default: break; } LogRichTextBox.Select(LogRichTextBox.Text.Length, 0); LogRichTextBox.SelectionColor = Color.Black; }
public void Log(ELogType logType, string log) { _strBuilder.Clear(); _strBuilder.AppendFormat(FORMAT, LOG_COLORS[(int)logType], DateTime.Now.ToString("HH:mm:ss"), log); _uLogger.Log(UnityEngine.LogType.Log, logType.ToString(), _strBuilder.ToString()); }
/// <summary> /// 记录日志 /// </summary> /// <param name="type"></param> /// <param name="message"></param> /// <param name="logLevel"></param> /// <returns></returns> public static bool WriteLog(ELogType type, string message, ELogLevel logLevel = ELogLevel.Info) { if (!_hadInit) { throw new Exception("请调用Init函数初始化本工具类"); } string identifier = HashHelper.GetMD5_16(type.ToString()); return(WriteLog(identifier, new LogInfo(message, logLevel))); }
/// <summary> /// 记录日志 /// </summary> /// <param name="type"></param> /// <param name="info"></param> /// <returns></returns> public static bool WriteLog(ELogType type, LogInfo info) { if (!_hadInit) { throw new Exception("请调用Init函数初始化本工具类"); } string identifier = HashHelper.GetMD5_16(type.ToString()); return(WriteLog(identifier, info)); }
/// <summary> /// 记录日志 /// </summary> /// <param name="logType">日志类型</param> /// <param name="priority">日志级别</param> /// <param name="ex">异常</param> /// <param name="message">错误消息</param> public static void SaveLog(ELogType logType, ELogPriority priority, string nameSpace, string message, string desc) { switch (priority) { case ELogPriority.Trace: logger.Trace(const_Error, logType.ToString(), nameSpace, message, desc); break; case ELogPriority.Debug: logger.Debug(const_Error, logType.ToString(), nameSpace, message, desc); break; case ELogPriority.Inf: logger.Info(const_Error, logType.ToString(), nameSpace, message, desc); break; case ELogPriority.Warn: logger.Warn(const_Error, logType.ToString(), nameSpace, message, desc); break; case ELogPriority.Error: logger.Error(const_Error, logType.ToString(), nameSpace, message, desc); break; case ELogPriority.Fatal: logger.Fatal(const_Error, logType.ToString(), nameSpace, message, desc); break; } }
/// <summary> /// 添加日志 /// </summary> /// <param name="type">日志类型</param> /// <param name="creator">当前操作人</param> /// <param name="billNo">订单编号</param> /// <param name="description">操作描述</param> /// <param name="module">模块</param> /// <param name="createTime">创建时间</param> /// <param name="remark">备注信息</param> /// <returns></returns> public static int Insert(ELogType type, string creator, string billNo, string description, string module, DateTime createTime, string remark) { string sql = "INSERT INTO WM_LOG(TYPE, OPERATOR, BILL_NO, DESCRIPTION, MODULAR, CREATE_TIME, REMARK) " + "VALUES(@Type, @Operator, @BillNo, @Description, @Modular, NOW(), @Remark)"; DynamicParameters parms = new DynamicParameters(); parms.Add("Type", type.ToString()); parms.Add("Operator", creator); parms.Add("BillNo", billNo); parms.Add("Description", description); parms.Add("Modular", module); parms.Add("Remark", remark); IMapper map = DatabaseInstance.Instance(); return(map.Execute(sql, parms)); }
public override void Description(StringBuilder builder) { // Nothing to display. if (message.Length == 0) { return; } string displayed = message; // Only consider display the message up to the newline. int newLineIndex = message.IndexOf('\n'); if (newLineIndex >= 0) { displayed = message.Substring(0, newLineIndex); } // Nothing to display. if (displayed.Length == 0) { return; } if (logType != ELogType.Normal) { builder.AppendLine(logType.ToString()); } // Cap the message length to display to keep things compact. int maxCharacters = 20; if (displayed.Length > maxCharacters) { builder.Append(displayed.Substring(0, maxCharacters)); builder.Append("..."); } else { builder.Append(displayed); } }
public String format(ELogType type, String message) { String data = default_format; data = data.Replace("{message}", message); data = data.Replace("{level}", type.ToString()); data = data.Replace("{time}", String.Format("{0:HH:mm:ss:fff}",DateTime.Now)); return data; }
public void ShowLog(ELogType type, string callerName, string value) { m_LogString.Append(string.Format(LINE_FORMAT, DateTime.Now.ToString("dd/MM/yyyy HH:mm"), type.ToString(), callerName, value)); m_ShowWindow = true; }
public static void WriteLogForEverDay(this string text, ELogType type) { LoggerWriter.CreateLogFile(text, Logdir + Logger.GetYearMonth() + "/" + DateTime.Now.ToString("yyyyMMdd") + "/", type, type.ToString(), true); }
/// <summary> /// 将数据写入到日志 /// </summary> /// <param name="text"></param> /// <param name="path"></param> /// <param name="log"></param> /// <param name="fileName"></param> /// <param name="existsWrite">存在相同名称的文件进行替换还是追加</param> public static void CreateLogFile(string text, string path, ELogType log, string fileName = null, bool existsWrite = false, Encoding encode = null) { if (string.IsNullOrEmpty(text)) { return; } if (!string.IsNullOrEmpty(path) && !Directory.Exists(path)) { Directory.CreateDirectory(path); } DateTime now = DateTime.Now; string file = path; if (!Directory.Exists(file)) { Directory.CreateDirectory(file); } string filetype = ".txt"; if (string.IsNullOrEmpty(fileName)) { file += "/" + now.ToString(CommonFormat.DateTimeIntFormat) + filetype; } else {//需要判断是否增加后缀 if (!fileName.Contains(".")) { file += "/" + fileName + filetype; } else { file += "/" + fileName; } } FileStream fs; if (!existsWrite) { fs = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.Write); } else { if (File.Exists(file)) { text = "\r\n" + text; fs = new FileStream(file, FileMode.Append, FileAccess.Write, FileShare.Write); } else { fs = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.Write); } } if (encode == null) { encode = Encoding.UTF8; } StreamWriter sw = new StreamWriter(fs, encode); StringBuilder sb = new StringBuilder(); sb.AppendLine(CreateSign()); sb.AppendLine(log.ToString()); sb.AppendLine(text); sw.Write(sb.ToString()); sw.Close(); fs.Close(); }
public int WriteLog(string strLog, ELogType logType, ELogWType writeType, bool bShowDebugLine = true, int skipFrames = 2) { // 0. initialize DateTime now = DateTime.Now; StackFrame sf = new StackFrame(skipFrames, true); string strMethodName = sf.GetMethod().ToString(); string sfFileName = sf.GetFileName(); int sfErrLine = sf.GetFileLineNumber(); if (sfFileName != null) { int iFound = sfFileName.LastIndexOf("\\"); if (iFound == -1) { iFound = sfFileName.LastIndexOf("/"); } if (iFound >= 0) { sfFileName = sfFileName.Substring(iFound); } sfFileName = sfFileName.Replace("\\", ""); sfFileName = sfFileName.Replace("/", ""); } // 0.5 show debug window strLog = strLog.Replace("\r\n", " "); strLog = strLog.Replace("'", ""); if (bShowDebugLine) { string log = $"{now.ToString("yyyy-MM-dd HH:mm:ss.fff")}, {logType.ToString()}, {writeType.ToString()}, {strLog}, ({sfFileName}, {sfErrLine.ToString()} line)"; Debug.WriteLine(log); } // 1. write log if (logType == ELogType.Debug) // Debug { if (writeType == ELogWType.Normal && IsWriteLog_Normal == false) { return(SUCCESS); } if (writeType == ELogWType.Warning && IsWriteLog_Warning == false) { return(SUCCESS); } if (writeType == ELogWType.Error && IsWriteLog_Error == false) { return(SUCCESS); } string create_query = $"CREATE TABLE IF NOT EXISTS {DBInfo.TableDebugLog} (Time datetime, Name string, Type string, Comment string, File string, Line string)"; string query = $"INSERT INTO {DBInfo.TableDebugLog} VALUES ('{DBManager.DateTimeSQLite(now)}', '{DebugTableName}', '{writeType.ToString()}', '{strLog}', '{sfFileName}', '{sfErrLine.ToString()}')"; DBManager.ExecuteNonQuerys(DBInfo.DBConn_DLog, create_query, query); } else if (logType == ELogType.Tact) // Tact { } else if (logType == ELogType.SECGEM) // SecGem { } else // Other Event { string create_query = $"CREATE TABLE IF NOT EXISTS {DBInfo.TableEventLog} (Time datetime, Name string, Type string, Comment string, File string, Line string)"; string query = $"INSERT INTO {DBInfo.TableEventLog} VALUES ('{DBManager.DateTimeSQLite(now)}', '{logType.ToString()}', '{writeType.ToString()}', '{strLog}', '{sfFileName}', '{sfErrLine.ToString()}')"; DBManager.ExecuteNonQuerys(DBInfo.DBConn_ELog, create_query, query); } return(SUCCESS); }