/// <summary> ///Catching exceptions/// </summary> protected voidApplication_Error () {//get an instance of the previous exception varex =Server.GetLastError (). GetBaseException (); { varSberror =NewStringBuilder (); Sberror.appendformat ("URL originalstring:{0}\r\n", Request.Url.OriginalString); Sberror.appendformat ("URL pathandquery:{0}\r\n", Request.Url.PathAndQuery); Sberror.appendformat ("URL. ToString (): {0}\r\n", Request.Url.ToString ()); Sberror.appendformat ("URL absoluteuri:{0}\r\n", Request.Url.AbsoluteUri); varquery = (string. IsNullOrEmpty (Request.Url.Query)?"":"?"+Request.Url.Query); Sberror.appendformat ("query:{0}\r\n", query); Sberror.appendformat ("time of occurrence: {0}\r\n", DateTime.Now.ToString ("yyyy-mm-dd HH:mm:ss FFFF")); Sberror.appendformat ("exception ip:{0}\r\n", PcHelper.GetInstance.GetIp ()); Sberror.appendformat ("Exception Computer name: {0}\r\n", PcHelper.GetInstance.GetUserHostName ()); Sberror.appendformat ("Browser: {0}\r\n", PcHelper.GetInstance.GetBrowser ()); varUrlrefer =string. Empty; if(Request.urlreferrer! =NULL) {Urlrefer=Request.UrlReferrer.OriginalString; } Sberror.appendformat ("Urlrefer originalstring:{0}\r\n", Urlrefer); Sberror.appendformat ("Error Time: {0}\r\n", DateTime.Now.ToString ("yyyy-mm-dd HH:mm:ss FFFF")); Sberror.appendformat ("Error File: {0}\r\n", ex. Source); Sberror.appendformat ("error message: {0}\r\n", ex. Message); Sberror.appendformat ("method that caused the error: {0}\r\n", ex. TargetSite); Sberror.appendformat ("Error Stack: {0}\r\n", ex. StackTrace); //logging errors to the logFileHelper.GetInstance.WriteToFile (Server.MapPath (Commonconst.errorlogpath), sberror.tostring ()); } }
Application_Error Exception Handling