コード例 #1
0
        /// <summary>
        /// Report an error that involves an exception
        /// </summary>
        /// <param name="errorObject">
        /// An object that describes the error (for example, an exception) or null
        /// </param>
        /// <param name="severity">The severity of the error</param>
        /// <param name="title">
        /// The title of the error (for example, Unhandled Exception)
        /// </param>
        /// <param name="message">
        /// An optional message that could provide extra details about the error
        /// </param>
        /// <param name="extraErrorDetails">
        /// A collection of extra details about the error where the key in the <see cref="KeyValuePair{TKey,TValue}"/>
        /// is the detail's name (ie Current Page) and the value is the object that is the detail (ie a string
        /// with the page URL).
        /// </param>
        public void ReportError(object errorObject, ErrorSeverity severity, string title, string message, IEnumerable <KeyValuePair <string, object> > extraErrorDetails)
        {
            ErrorReportingConfigurationSection settings = ErrorReportingConfigurationSection.GetSection();

            if (settings.IsEnabled == false)
            {
                return;
            }

            if (errorObject != null)
            {
                //Check to see whether any of the Ignore rules match the exception
                foreach (Predicate <object> rule in _IgnoreRules)
                {
                    if (rule(errorObject))
                    {
                        return;                         //Matched, ignore this exception
                    }
                }
            }

            MailAddress from = new MailAddress(settings.SendFromEmail.Address, settings.SendFromEmail.DisplayName);
            MailAddress to   = new MailAddress(settings.SendToEmail.Address, settings.SendToEmail.DisplayName);

            MailMessage msg = new MailMessage(from, to);

            msg.IsBodyHtml = _Composer.IsHtmlEmail;
            msg.Body       = _Composer.ComposeEmailBody(errorObject, severity, title, message, extraErrorDetails);
            msg.Subject    = _Composer.ComposeEmailSubject(errorObject, severity, title, message);

            SmtpClient smtp = new SmtpClient();

            smtp.Send(msg);
        }
コード例 #2
0
 /// <summary>
 /// Constructor, creates a <see cref="ErrorReporter"/> object that renders its
 /// emails using a specific <see cref="IErrorEmailComposer"/>
 /// </summary>
 /// <param name="composer">The Composer with which to render emails</param>
 public ErrorReporter(IErrorEmailComposer composer)
 {
     _Composer    = composer;
     _IgnoreRules = new List <Predicate <object> >();
     ErrorReportingConfigurationSection.GetSection();             //Causes a check for the presence of configuration
 }