c#写日志的函数
2017-06-12 12:44 伟大的程序员2 阅读(225) 评论(0) 编辑 收藏 举报public class LogClass
{
public void Write(string content)
{
try
{
var directoryPath = System.Windows.Forms.Application.StartupPath;
var filePath = directoryPath + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + "a.log";
File.AppendAllText(filePath, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
File.AppendAllText(filePath, Environment.NewLine);
File.AppendAllText(filePath, content);
File.AppendAllText(filePath, Environment.NewLine);
}
catch (Exception ex)
{
Console.Write(ex.ToString());
}
}
}