public static class Log { private static object lockerForError = new object(); //错误日志锁 /// <summary> /// 保存错误日志 /// </summary> /// <param name="source"></param> /// <param name="type"></param> /// <param name="error"></param> public static void SaveLog(string source, string type, string error) { try { if (CommonParameter.IsSaveErrorLog == 1) { lock (lockerForError) { string strCurPath = AppDomain.CurrentDomain.BaseDirectory.ToString(); string strErrorLogPath = Path.Combine(strCurPath, "ErrorLog"); string strErrorLogFile = Path.Combine(strErrorLogPath, DateTime.Now.ToString("yyyyMMdd") + ".log"); if (!Directory.Exists(strErrorLogPath)) { Directory.CreateDirectory(strErrorLogPath); } FileStream fs = new FileStream(strErrorLogFile, FileMode.OpenOrCreate); StreamWriter streamWriter = new StreamWriter(fs); streamWriter.BaseStream.Seek(0, SeekOrigin.End); streamWriter.WriteLine("[" + DateTime.Now.ToString() + "]/r/nSource : " + source + "/r/nError : [" + type + "]" + error + "/r/n"); streamWriter.Flush(); streamWriter.Close(); fs.Close(); } } } catch (Exception exception) { } } }