首页 > 代码库 > C# 利用file打印日志
C# 利用file打印日志
public class FaceLog { public static void AppendInfoLog(string errMsg) { try { string Folder = Main.Instance.AppPath + "\\Logs\\"; string fileName = Folder + "Info_" + DateTime.Now.ToString("yyyyMMdd") + ".txt"; if (!System.IO.Directory.Exists(Folder)) System.IO.Directory.CreateDirectory(Folder); if (!File.Exists(fileName)) System.IO.File.Create(fileName); using (TextWriter fs = new StreamWriter(fileName, true)) { fs.WriteLine("--------------------------" + DateTime.Now.ToString() + "----------------------------------------"); fs.WriteLine(errMsg); fs.WriteLine(""); fs.WriteLine(""); fs.Close(); fs.Dispose(); } } catch { } } public static void AppendErrorLog(string errMsg) { try { string Folder = Main.Instance.AppPath + "\\Logs\\"; string fileName = Folder + "Error_" + DateTime.Now.ToString("yyyyMMdd") + ".txt"; if (!System.IO.Directory.Exists(Folder)) System.IO.Directory.CreateDirectory(Folder); if (!File.Exists(fileName)) System.IO.File.Create(fileName); using (TextWriter fs = new StreamWriter(fileName, true)) { fs.WriteLine("--------------------------" + DateTime.Now.ToString() + "----------------------------------------"); fs.WriteLine(errMsg); fs.WriteLine(""); fs.WriteLine(""); fs.Close(); fs.Dispose(); } } catch { } } }
C# 利用file打印日志
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。