/// <summary> /// 构造函数 /// </summary> /// <param name="norM">一般日志信息</param> /// <param name="type">日志类型</param> public LogMessage(string norM, LogErroType type) { this.NormalMessage = norM; this.DetailMessage = ""; this.Type = type; LogTime = DateTime.Now; }
/// <summary> /// 构造函数 /// </summary> /// <param name="ex">异常信息(默认为一般日志)</param> public LogMessage(Exception ex) { this.NormalMessage = ex.Message; this.DetailMessage = ex.ToString(); this.Type = LogErroType.Waring; LogTime = DateTime.Now; }
/// <summary> /// 构造函数 /// </summary> /// <param name="msg">一般信息</param> /// <param name="ex">详细异常</param> /// <param name="type">日志类型</param> public LogMessage(string msg, Exception ex, LogErroType type = LogErroType.Erro) { this.NormalMessage = msg + " " + ex.Message; this.DetailMessage = ex.ToString(); this.Type = type; this.LogTime = DateTime.Now; }
/// <summary> /// 打印进度 /// </summary> /// <param name="current">进度</param> /// <param name="max">最多的格子</param> public void Progress(float current, string taskname = "进度", int max = 20, LogErroType logErroType = LogErroType.Normal) { if (current > 1) { return; } float value = ((float)max * current); int pboxs = (int)value; float point = value - pboxs; string processstring = ""; for (int i = 0; i < max; i++) { if (i < pboxs) { processstring += f11; } else if (i > pboxs) { processstring += " "; } else if (i == pboxs && pboxs != 0 && point != 0f) { if (point > 0 && point <= 1.0f / 8.0f) { processstring += f18; } else if (point > 1.0f / 8.0f && point <= 1.0f / 4.0f) { processstring += f14; } else if (point > 1.0f / 4.0f && point <= 3.0f / 8.0f) { processstring += f38; } else if (point > 3.0f / 8.0f && point <= 1.0f / 2.0f) { processstring += f12; } else if (point > 1.0f / 2.0f && point <= 5.0f / 8.0f) { processstring += f58; } else if (point > 5.0f / 8.0f && point <= 3.0f / 4.0f) { processstring += f34; } else if (point > 3.0f / 4.0f && point <= 7.0f / 8.0f) { processstring += f78; } else { processstring += f11; } } } LogInfo.WriteToFile(this, new LogMessage(taskname, write(" : [", processstring, "]", current * 100, "%"), logErroType)); }