以下为Txt的创建和写入操作
public void WriteLogTxt(string message)
{
if (!File.Exists("C:\\SCETestLog.txt"))
{
//创建
FileStream fs1 = new FileStream("C:\\SCETestLog.txt", FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs1);
//开始写入值
sw.WriteLine("Log:" + DateTime.Now.ToString() + "\r\n" + "[" + DateTime.Now.ToString() + "]LogMessage:" + message + "\n");
sw.Close();
fs1.Close();
}
else
{
//写入
FileStream fs = new FileStream("C:\\SCETestLog.txt", FileMode.Append, FileAccess.Write);
StreamWriter sr = new StreamWriter(fs);
sr.WriteLine("[" + DateTime.Now.ToString() + "]LogMessage:" + message + "\n");//开始写入值
sr.Close();
fs.Close();
}
}