怎么在C#中实现这个功能,怎么将textBox里的内容追回到D盘目录下的log.txt里?

来源:百度知道 编辑:UC知道 时间:2024/06/21 15:06:20

WriteLog(@"d:\log.txt",textBox.Text)
/// <summary>
/// 写入日志
/// </summary>
/// <param name="content"></param>
public static void WriteLog(string fileName, string content)
{
string path = Util.GetMapPath(fileName);
try
{
if (!System.IO.File.Exists(path))
{
StreamWriter sw = System.IO.File.CreateText(path);
sw.WriteLine("---日志开始---" + DateTime.Now.ToString());
sw.Flush();
sw.Close();
}
StreamWriter sw2 = System.IO.File.AppendText(path);
sw2.WriteLine("--" + DateTime.Now.ToString() + "---" + content);
sw2.Flush();
sw2.Close();
}