您的位置:首页 > 其它

一个简单的日志类,测试时候用

2007-08-31 02:50 417 查看
class LogWriter

2 {

3 private static string path = Application.StartupPath + "\\log.txt";

4 static LogWriter()

5 {

6

7 if (!File.Exists(path))

8 {

9 FileStream fs = File.Create(path);

fs.Close();

}

Log("Log Start:");

}

public static void Log(string str)

{

StreamWriter sw = File.AppendText(path);

sw.WriteLine(DateTime.Now.ToLongTimeString() + ": " + str);

sw.Close();

}

public static void Error(string str)

{

StreamWriter sw = File.AppendText(path);

sw.WriteLine(DateTime.Now.ToLongTimeString() + ": Error " + str);

sw.Close();

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐