/// <summary> /// 写日志 /// </summary> /// <param name="strSubSys">子系统,默认为Sys</param> /// <param name="logType">日志类型</param> /// <param name="logGrade">警告级别</param> /// <param name="errorMessage">日志内容</param> public void WriteLog(string strSubSys, LogType logType, LogGrade logGrade, string errorMessage, string strExt1, string strExt2) { string strLog = string.Format("{0,-20};{1,-10};{2,-10};{3,-10};ex{4:-10};ex{5:-10};{6,-10}", DateTime.Now, strSubSys, EnumTextByDescription.GetEnumDesc(logType), EnumTextByDescription.GetEnumDesc(logGrade), errorMessage, strExt1, strExt2); System.Diagnostics.Trace.WriteLine(strLog); }
/// <summary> /// 写日志 /// </summary> /// <param name="strSubSys">子系统,默认为Sys</param> /// <param name="logType">日志类型</param> /// <param name="logGrade">警告级别</param> /// <param name="errorMessage">日志内容</param> public void WriteLog(string strSubSys, LogType logType, LogGrade logGrade, string errorMessage, string strExt1, string strExt2) { try { System.Diagnostics.Trace.WriteLine(AppDomain.CurrentDomain.BaseDirectory + "FileLogs"); string logPath = string.Format("{0}filelogs\\{1}", AppDomain.CurrentDomain.BaseDirectory, strFileName); if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "FileLogs")) { Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "FileLogs"); } lock (lockObj) { FileInfo fi = new FileInfo(logPath); if (fi.Exists && fi.Length > iFileLen) { FileCopy(logPath); fi.Delete(); } using (StreamWriter sw = new StreamWriter(logPath, true, Encoding.Unicode)) { sw.WriteLine(string.Format("{0,-20};{1,-10};{2,-10};{3,-10};{4,-10};{5,-10};{6,-10}", DateTime.Now, strSubSys, EnumTextByDescription.GetEnumDesc(logType), EnumTextByDescription.GetEnumDesc(logGrade), strExt1, strExt2, errorMessage)); } } } catch (Exception ex) { System.Diagnostics.Trace.Write(ex.Message); } }