嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
个人使用的日志记录,主要是方便,不用配置,方便个人写测试程序的时候使用,或是学习使用;
/// <summary>
/// 创建文件
/// </summary>
/// <returns></returns>
public static Boolean CreateLogFile()
{
try
{
strFilePath = Application.StartupPath "\\日志";
if (!Directory.Exists(strFilePath))
{
Directory.CreateDirectory(strFilePath);
}
strFilePath = "\\" DateTime.Now.ToString("yyyy-MM-dd") strFileName;
if (!File.Exists(strFilePath))
{
//File.Create(strFilePath);
FileStream fs1 = new FileStream(strFilePath, FileMode.Create, FileAccess.Write);//创建写入文件
StreamWriter sw1 = new StreamWriter(fs1);
sw1.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") ":" "系统启动");//开始写入值
sw1.Close();
fs1.Close();
}
return true;
}
catch (Exception ex)
{
MessageBox.Show("日志记录创建失败!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}