#region 读写log日志
string strMsg = string.Empty;
string LogName = "F:\\TestLog.txt"; //txt文件路
//string LogName = System.Web.HttpContext.Current.Server.MapPath("\\TestLog.txt")
if (!File.Exists(LogName)) //判断txt文件是否存在
{
FileStream fsnew = File.Create(LogName); //创建txt文件
fsnew.Close();
}
using (FileStream fs = File.Open(LogName, FileMode.Append, FileAccess.Write))
{
using (StreamWriter w = new StreamWriter(fs)) //向txt文件中添加内容
{
#region
w.BaseStream.Seek(0, SeekOrigin.End);
w.WriteLine("=====================================");
w.Write("添加日期为:" + DateTime.Now.ToString() + "\r\n");
//w.Write("日志内容为:" + strMsg + "\r\n");
w.WriteLine("=====================================");
w.Flush();
w.Close();
#endregion
}
}
#endregion
读写txt文件
最新推荐文章于 2023-01-18 10:00:00 发布