public static void ErrorLog(string mssg)
{
string FilePath = "D:/logs/ErrorLog.txt";
try
{
if (System.IO.File.Exists(FilePath))
{
using (StreamWriter tw = System.IO.File.AppendText(FilePath))
{
tw.WriteLine(DateTime.Now.ToString() + "> " + mssg);
} //END using
} //END if
else
{
StreamWriter 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
原文:http://www.cnblogs.com/Zing/p/5212066.html