首页 > 代码库 > 简单的日志类
简单的日志类
class LogHelper { string logFile = ""; /// <summary> /// 不带参数的构造函数 /// </summary> public LogHelper() { } /// <summary> /// 带参数的构造函数 /// </summary> /// <param name="logFile"></param> public LogHelper(string logFile) { this.logFile = logFile; } /// <summary> /// 追加一条信息 /// </summary> /// <param name="text"></param> public void Write(string text) { using (StreamWriter sw = new StreamWriter(logFile, true, Encoding.UTF8)) { sw.Write(DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss] ") + text); } } /// <summary> /// 追加一条信息 /// </summary> /// <param name="logFile"></param> /// <param name="text"></param> public void Write(string logFile, string text) { using (StreamWriter sw = new StreamWriter(logFile, true, Encoding.UTF8)) { sw.Write(DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss] ") + text); } } /// <summary> /// 追加一行信息 /// </summary> /// <param name="text"></param> public void WriteLine(string text) { text += "\r\n"; using (StreamWriter sw = new StreamWriter(logFile, true, Encoding.UTF8)) { sw.Write(DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss] ") + text); } } /// <summary> /// 追加一行信息 /// </summary> /// <param name="logFile"></param> /// <param name="text"></param> public void WriteLine(string logFile, string text) { text += "\r\n"; using (StreamWriter sw = new StreamWriter(logFile, true, Encoding.UTF8)) { sw.Write(DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss] ") + text); } } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。