try
{}
catch(Exception ex)
{
cm.Connection.Close() ;
qiao.Value ="fail";
PublicUnit.SaveError(ex,this.Context,this.Request) ;
}

//写日志的编写
public static void SaveError(Exception ex,HttpContext hc,HttpRequest hr)
{
string temp ;
StreamWriter sw ;
//如果存在文件
if(File.Exists(hr.PhysicalApplicationPath+@"\Error.txt"))
{
sw = File.AppendText(hr.PhysicalApplicationPath+@"\Error.txt") ;
temp = DateTime.Now.ToString() + "------------------------------------------------------------------------------------\n";
temp += "错误消息:" + ex.Message +"\n";
temp += "导致错误的应用程序或对象的名称:" + ex.Source +"\n";
temp += "堆栈内容:" + ex.StackTrace +"\n";
temp += "引发异常的方法:" + ex.TargetSite +"\n";
temp += "错误页面" +hr.RawUrl + "\n\n";
sw.WriteLine(temp) ;
sw.Close() ;
}
}
http://www.cnblogs.com/catbim/archive/2006/04/11/372464.html

