DateTime dt = DateTime.Now;
string filename = dt.ToString("yyyy-MM-dd") + "_log.txt";
string path =System.AppDomain.CurrentDomain.BaseDirectory+ "log\\";
System.Diagnostics.Trace.WriteLine(path);
FileStream fs;
if (!File.Exists(path + filename))
{
fs = new FileStream(path + filename, FileMode.Create, FileAccess.Write);
}
else {
fs = new FileStream(path + filename, FileMode.Open, FileAccess.Write);
}
//追加写入
StreamWriter sw = new StreamWriter(fs);
long fl = fs.Length;
fs.Seek(fl, SeekOrigin.Begin);
sw.WriteLine(DateTime.Now.ToString() + "\n_S:________ \n" + msg + "\n __________End.\n");//开始写入值
//结束
sw.Close();
fs.Close();