using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace WCS { public class WriteSysLog { private static string LogName2 = "Log"; /// /// 写日志 /// /// public static void SysLog(string strLog) { lock ("SysLog") { try { strLog = strLog + Environment.NewLine; DirectoryInfo di = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "\\" + LogName2); if (di.Exists == false) { di.Create(); } string logFileName; logFileName = AppDomain.CurrentDomain.BaseDirectory + "\\" + LogName2 + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".log"; if (File.Exists(logFileName)) { FileInfo fi = new FileInfo(logFileName); } StreamWriter sw = null; FileStream fs = new FileStream(logFileName, FileMode.Append, FileAccess.Write, FileShare.ReadWrite); sw = new StreamWriter(fs); sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff") + "||" + strLog); sw.Close(); } catch { } } } } }