static void slackReportEvented_OnExceptionReporting(ExceptionReportingEventArgs args) { args.Options = new WebHookOptions(ConfigurationManager.AppSettings["slack:webhookurl"]) { Text = "Options reported via the event.", ChannelName = ConfigurationManager.AppSettings["slack:channel"], }; // args.CancelReport = true; }
public void OnException(ExceptionContext filterContext) { // auto eject if // ...ignoring handled exceptions if (IgnoreHandled && filterContext.ExceptionHandled) { return; } var exception = filterContext.Exception; // ...the exception type is in the ignore list if (IgnoreExceptionTypes != null && IgnoreExceptionTypes.Length > 0 && IgnoreExceptionTypes.Contains(exception.GetType())) { return; } var options = Options; // is the event set? if (OnExceptionReporting != null) { var reportingArgs = new ExceptionReportingEventArgs(exception) { Options = options }; OnExceptionReporting(reportingArgs); // did event handler tell us to cancel the error report? if (reportingArgs.CancelReport) { // eject! return; } // grab the options back from the args in case it was created new. options = reportingArgs.Options; } if (options == null) { throw new NullReferenceException( "The WebHookErrorReportFilter.Options must be set as it contains the details for connecting to the Slack web hook. Use any one of: new WebHookErrorReportFilter(WebHookOptions options); WebHookErrorReportFilter.Options setter; OnExceptionReporting event ExceptionReportingEventArgs.Options property."); } var reportedArgs = new ExceptionReportedEventArgs() { Options = options, Exception = exception }; try { var reporter = _client == null ? new WebHookExceptionReporter(options.WebhookUrl) : new WebHookExceptionReporter(_client); reportedArgs.ReportSucceeded = reporter.ReportException(exception, options); } catch (Exception ex) { reportedArgs.ReportException = ex; } if (OnExceptionReported != null) { OnExceptionReported(reportedArgs); } if (!reportedArgs.ReportSucceeded && ThrowOnFailure) { throw reportedArgs.ReportException; } }
public void OnException(ExceptionContext filterContext) { // auto eject if // ...ignoring handled exceptions if(IgnoreHandled && filterContext.ExceptionHandled) return; var exception = filterContext.Exception; // ...the exception type is in the ignore list if(IgnoreExceptionTypes != null && IgnoreExceptionTypes.Length > 0 && IgnoreExceptionTypes.Contains(exception.GetType())) return; var options = Options; // is the event set? if(OnExceptionReporting != null) { var reportingArgs = new ExceptionReportingEventArgs(exception) {Options = options}; OnExceptionReporting(reportingArgs); // did event handler tell us to cancel the error report? if(reportingArgs.CancelReport) { // eject! return; } // grab the options back from the args in case it was created new. options = reportingArgs.Options; } if(options == null) { throw new NullReferenceException( "The WebHookErrorReportFilter.Options must be set as it contains the details for connecting to the Slack web hook. Use any one of: new WebHookErrorReportFilter(WebHookOptions options); WebHookErrorReportFilter.Options setter; OnExceptionReporting event ExceptionReportingEventArgs.Options property."); } var reportedArgs = new ExceptionReportedEventArgs() { Options = options, Exception = exception }; try { var reporter = _client == null ? new WebHookExceptionReporter(options.WebhookUrl) : new WebHookExceptionReporter(_client); reportedArgs.ReportSucceeded = reporter.ReportException(exception, options); } catch(Exception ex) { reportedArgs.ReportException = ex; } if(OnExceptionReported != null) { OnExceptionReported(reportedArgs); } if(!reportedArgs.ReportSucceeded && ThrowOnFailure) { throw reportedArgs.ReportException; } }