public class Log { /// <summary> /// 写日志,指定日志文件 /// </summary> /// <param name="File"></param> /// <param name="Msg"></param> public static void Add(string File,string Msg) { try { if (!System.IO.File.Exists(File)) { System.IO.File.CreateText(File).Dispose(); } using (TextWriter writer2 = System.IO.File.AppendText(File)) { writer2.WriteLine(Msg); writer2.WriteLine(" "); } } catch (Exception ex) { } } /// <summary> /// 写日志,缺省日志在程序目录下的Log.txt文件 /// </summary> /// <param name="Msg"></param> public static void Add(string Msg) { try { string path = string.Format(@"{0}\{1}", AppDomain.CurrentDomain.BaseDirectory, "Log.txt"); if (!System.IO.File.Exists(path)) { System.IO.File.CreateText(path).Dispose(); } using (TextWriter writer2 = System.IO.File.AppendText(path)) { writer2.WriteLine(Msg); writer2.WriteLine(" "); } } catch (Exception ex) { } } }
时间: 2024-10-26 18:44:20