异常错误处理在文本文件中? [英] Exception Error Handling In a textfile?
本文介绍了异常错误处理在文本文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在记事本文件中保存异常..
我尝试使用此代码..
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.
这篇关于异常错误处理在文本文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文