protected virtual void OnErrorModuleFiltering(object sender, ExceptionFilterEventArgs args) { if (args == null) throw new ArgumentNullException("args"); if (args.Exception == null) throw new ArgumentException(null, "args"); try { if (Assertion.Test(new AssertionHelperContext(sender, args.Exception, args.Context))) args.Dismiss(); } catch (Exception e) { Trace.WriteLine(e); throw; } }
/// <summary> /// Raises the <see cref="Filtering"/> event. /// </summary> protected virtual void OnFiltering(ExceptionFilterEventArgs args) { ExceptionFilterEventHandler handler = Filtering; if (handler != null) handler(this, args); }
/// <summary> /// Reports the exception. /// </summary> protected virtual void OnError(Exception e, HttpContext context) { if (e == null) throw new ArgumentNullException("e"); // // Fire an event to check if listeners want to filter out // reporting of the uncaught exception. // ExceptionFilterEventArgs args = new ExceptionFilterEventArgs(e, context); OnFiltering(args); if (args.Dismissed) return; // // Get the last error and then report it synchronously or // asynchronously based on the configuration. // Error error = new Error(e, context); if (_reportAsynchronously) ReportErrorAsync(error); else ReportError(error); }
/// <summary> /// Logs an exception and its context to the error log. /// </summary> protected virtual void LogException(Exception e, HttpContext context) { if (e == null) throw new ArgumentNullException("e"); // // Fire an event to check if listeners want to filter out // logging of the uncaught exception. // ExceptionFilterEventArgs args = new ExceptionFilterEventArgs(e, context); OnFiltering(args); if (args.Dismissed) return; // // Log away... // ErrorLogEntry entry = null; try { Error error = new Error(e, context); ErrorLog log = GetErrorLog(context); string id = log.Log(error); entry = new ErrorLogEntry(log, id, error); } catch (Exception localException) { // // IMPORTANT! We swallow any exception raised during the // logging and send them out to the trace . The idea // here is that logging of exceptions by itself should not // be critical to the overall operation of the application. // The bad thing is that we catch ANY kind of exception, // even system ones and potentially let them slip by. // Trace.WriteLine(localException); } if (entry != null) OnLogged(new ErrorLoggedEventArgs(entry)); }
/// <summary> /// Logs an exception and its context to the error log. /// </summary> protected virtual void LogException(Exception e, HttpContext context) { if (e == null) throw new ArgumentNullException("e"); // // Fire an event to check if listeners want to filter out // logging of the uncaught exception. // ExceptionFilterEventArgs args = new ExceptionFilterEventArgs(e, context); OnFiltering(args); if (args.Dismissed) return; // // Tweet away... // HttpWebRequest request = null; try { string status = StringFormatter.Format(_statusFormat, new Error(e, context)); // // Apply ellipsis if status is too long. If the trimmed // status plus ellipsis yields nothing then just use // the trimmed status without ellipsis. This can happen if // someone gives an ellipsis that is ridiculously long. // int maxLength = _maxStatusLength; if (status.Length > maxLength) { string ellipsis = _ellipsis; int trimmedStatusLength = maxLength - ellipsis.Length; status = trimmedStatusLength >= 0 ? status.Substring(0, trimmedStatusLength) + ellipsis : status.Substring(0, maxLength); } // // Submit the status by posting form data as typically down // by browsers for forms found in HTML. // request = (HttpWebRequest) WebRequest.Create(_url); request.Method = "POST"; // WebRequestMethods.Http.Post; request.ContentType = "application/x-www-form-urlencoded"; if (_credentials != null) // Need Basic authentication? { request.Credentials = _credentials; request.PreAuthenticate = true; } // See http://blogs.msdn.com/shitals/archive/2008/12/27/9254245.aspx request.ServicePoint.Expect100Continue = false; // // URL-encode status into the form and get the bytes to // determine and set the content length. // string encodedForm = string.Format(_formFormat, HttpUtility.UrlEncode(status)); byte[] data = Encoding.ASCII.GetBytes(encodedForm); Debug.Assert(data.Length > 0); request.ContentLength = data.Length; // // Get the request stream into which the form data is to // be written. This is done asynchronously to free up this // thread. // // NOTE: We maintain a (possibly paranoid) list of // outstanding requests and add the request to it so that // it does not get treated as garbage by GC. In effect, // we are creating an explicit root. It is also possible // for this module to get disposed before a request // completes. During the callback, no other member should // be touched except the requests list! // _requests.Add(request); IAsyncResult ar = request.BeginGetRequestStream( new AsyncCallback(OnGetRequestStreamCompleted), AsyncArgs(request, data)); } catch (Exception localException) { // // IMPORTANT! We swallow any exception raised during the // logging and send them out to the trace . The idea // here is that logging of exceptions by itself should not // be critical to the overall operation of the application. // The bad thing is that we catch ANY kind of exception, // even system ones and potentially let them slip by. // OnWebPostError(request, localException); } }