C#写入日志到文本文件的代码
using System.IO;
public static void ErrorLog(string mssg) {
string FilePath = HttpContext.Current.Server.MapPath("~/log/ErrorLog.txt");
try
{
if (File.Exists(FilePath))
{
using (StreamWriter tw = File.AppendText(FilePath))
{
tw.WriteLine(DateTime.Now.ToString() + "> " + mssg);
} //END using
} //END if
else
{
TextWriter tw = new StreamWriter(FilePath);
tw.WriteLine(DateTime.Now.ToString() + "> " + mssg);
tw.Flush();
tw.Close();
tw = null;
} //END else
} //END Try
catch (Exception ex)
{ } //END Catch
} // END ErrorLog
