异常错误处理在文本文件中?

问题描述:

我想在记事本文件中保存异常..

我尝试使用此代码..

I want to save the exception in Notepad File..
I tried with this Code..

Try
{
     // Code..
}
catch (Exception ex)
 {

     File.WriteAllText(Server.MapPath("~/Error.txt"), "Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
         "" + Environment.NewLine + "Date" + DateTime.Now.ToString());
     string New = Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine;
     File.AppendAllText(Server.MapPath("~/Error.txt"), New);

}



它保存了最后一个例外..但我想保存所有例外..意思是最后一个弱点,或者最后一个month..etc ...



请帮帮我


It save the Last Exception..But i want to save all exceptions..means last weak ,or last month..etc...

please help me

File.WriteAllText(Server.MapPath("~/Error.txt"),



更改为此




change to this

File.AppendAllText(Server.MapPath("~/Error.txt"),





看到 WriteAllText [ ^ ]和 AppendAllText [ ^ ]


不要使用File.WriteAllText - 它每次都会创建一个新文件。

尝试 File.AppendAllText [ ^ ]方法。
Don't use File.WriteAllText then - it creates a new file each time.
Try File.AppendAllText[^] method instead.