public static void GetExceptions(Exception oCurrentException, ErrorTracker.ErrorInfo oErrorInfo) { string sFullTrace = string.Empty; string strInnerErrorType = string.Empty; string strErrorTrace = string.Empty; string strErrorLine = string.Empty; string strErrorFile = string.Empty; string strErrorMessage = string.Empty; string strErrorPage = System.Web.HttpContext.Current.Request.PhysicalPath; StringBuilder oSB = new StringBuilder(); AppendTableHeader(oSB); oSB.Append("<tr>"); oSB.Append("<td colspan=2><h3>Exceptions</h3></td>"); oSB.Append("</tr>"); bool bFirstStepDown = true; while (oCurrentException != null) { Exception exInnerError = oCurrentException; if (exInnerError != null) { strInnerErrorType = exInnerError.GetType().ToString(); switch (strInnerErrorType) { // ascx/aspx compile error case "System.Web.HttpCompileException": System.CodeDom.Compiler.CompilerErrorCollection colErrors = ((System.Web.HttpCompileException)exInnerError).Results.Errors; if (colErrors.Count > 0) { strErrorLine = colErrors[0].Line.ToString(); strErrorFile = colErrors[0].FileName; strErrorMessage = colErrors[0].ErrorNumber + ": " + colErrors[0].ErrorText; } break; // any other error like XML parsing or bad string manipulations default: System.Diagnostics.StackTrace stError = new System.Diagnostics.StackTrace(exInnerError, true); for (int i = 0; i < stError.FrameCount; i++) { if (stError.GetFrame(i).GetFileName() != null) { strErrorLine = stError.GetFrame(i).GetFileLineNumber().ToString(); strErrorFile = stError.GetFrame(i).GetFileName(); strErrorMessage = exInnerError.Message; break; } } if (strErrorFile == "") { strErrorMessage = exInnerError.Message; strErrorFile = "Unknown"; } break; } strErrorTrace = exInnerError.StackTrace; sFullTrace += strErrorTrace; } else { strErrorMessage = oCurrentException.Message; strErrorTrace = oCurrentException.StackTrace; strErrorFile = "Unknown"; } if (strErrorMessage.IndexOf("This is an invalid webresource request.") > -1) { if (DisableTelerikWebResourceException) { throw new TelerikWebResourceException(); } } else if (strErrorMessage.IndexOf("Application is restarting") > -1) { throw new ApplicationStartException(); } if ((strInnerErrorType != null) && (strInnerErrorType.Trim().Length > 0)) { AppendTableRow(oSB, "Type", strInnerErrorType, true); } if ((strErrorMessage != null) && (strErrorMessage.Trim().Length > 0)) { AppendTableRow(oSB, "Message", strErrorMessage, true, "color:red;"); } if ((strErrorFile != null) && (strErrorFile.Trim().Length > 0)) { AppendTableRow(oSB, "Error File", CreateAnchor(strErrorFile), true); } if ((strErrorLine != null) && (strErrorLine.Trim().Length > 0)) { AppendTableRow(oSB, "Error Line", strErrorLine, true); } if ((strErrorTrace != null) && (strErrorTrace.Trim().Length > 0)) { AppendTableRow(oSB, "StackTrace", strErrorTrace.Replace("\n", "<br />"), true); } oSB.Append("<tr>"); oSB.Append("<td colspan2> </td>"); oSB.Append("</tr>"); if (bFirstStepDown) { oErrorInfo.Name = strInnerErrorType; oErrorInfo.ExceptionType = strInnerErrorType; oErrorInfo.ErrorLineNumber = string.Empty == strErrorLine ? 0 : Convert.ToInt32(strErrorLine); oErrorInfo.SourceFile = strErrorFile; oErrorInfo.Description = strErrorMessage; } oCurrentException = oCurrentException.InnerException; bFirstStepDown = false; } AppendTableFooter(oSB); AppendHr(oSB); // 1line if (strErrorTrace != null) { oErrorInfo.StackTrace = strErrorTrace.Replace("\n", "<br />"); } if ((oErrorInfo.Name == null) || (oErrorInfo.Name.Length == 0)) { oErrorInfo.Name = "Unknown Exception"; } oErrorInfo.ExceptionsDescription = oSB.ToString(); }
public static ErrorTracker.ErrorInfo SendError(Exception ex) { if (ex == null) { return(null); } ErrorTracker.ErrorInfo oErrorInfo = null; if (null == System.Web.HttpContext.Current) { return(null); } oErrorInfo = new ErrorTracker.ErrorInfo(); #region Collecting ErrorInfo Data oErrorInfo.ApplicationID = Convert.ToInt32(ConfigurationManager.AppSettings["ApplicationID"]); try { WebException.GetExceptions(ex, oErrorInfo); } catch (TelerikWebResourceException) { return(null); } catch (ApplicationStartException) { System.Web.HttpContext.Current.Response.Clear(); System.Web.HttpContext.Current.Response.Buffer = false; System.Web.HttpContext.Current.Response.Write("Error, Site is restarting. Try again later."); System.Web.HttpContext.Current.Response.Flush(); System.Web.HttpContext.Current.Response.End(); return(null); } oErrorInfo.Browser = System.Web.HttpContext.Current.Request.Browser.Browser; oErrorInfo.PhysicalFileName = System.Web.HttpContext.Current.Request.PhysicalPath; oErrorInfo.UserIPAddress = System.Web.HttpContext.Current.Request.UserHostAddress.ToString(); oErrorInfo.UserHostName = System.Web.HttpContext.Current.Request.UserHostName.ToString(); oErrorInfo.ErrorFile = System.Web.HttpContext.Current.Request.Url.LocalPath; oErrorInfo.URL = System.Web.HttpContext.Current.Request.Url.AbsoluteUri; oErrorInfo.URLReferrer = null != System.Web.HttpContext.Current.Request.UrlReferrer ? System.Web.HttpContext.Current.Request.UrlReferrer.AbsoluteUri : "None"; oErrorInfo.MachineName = System.Web.HttpContext.Current.Server.MachineName.ToString(); oErrorInfo.Version = WebException.GetVersionNumbers(); oErrorInfo.Form = WebException.GetForm(); oErrorInfo.Session = WebException.GetSession(); oErrorInfo.QueryString = System.Web.HttpContext.Current.Request.QueryString.ToString(); oErrorInfo.QueryStringDescription = WebException.GetQueryString(); oErrorInfo.ApplicationDescription = WebException.GetApplication(); oErrorInfo.RequestCookies = WebException.GetRequestCookies().ToString(); oErrorInfo.ResponseCookies = WebException.GetResponseCookies().ToString(); oErrorInfo.ServerVariables = WebException.GetServerVariables().ToString(); string cacheItemsInfo = ""; oErrorInfo.CacheSize = WebException.GetCacheSize(ref cacheItemsInfo); oErrorInfo.CacheItemsInfo = cacheItemsInfo; #endregion string errorInfoText = SerializeErrorInfo(oErrorInfo); oErrorInfo.QueryStringDescription += string.Format("<br/><hr/>Error Info length: {0}<hr/>", errorInfoText.Length); ErrorTracker.Service service = new Micajah.ErrorTrackerHelper2.ErrorTracker.Service(); service.AddError(oErrorInfo); return(oErrorInfo); }