コード例 #1
0
        private async Task ReportAsync(Dictionary <string, string> details, ExceptionToHandle exc = null)
        {
            string subject = $"[{_options.EnvironmentName}][Error] ";

            if (exc != null)
            {
                subject += exc.ExceptionType;
            }
            else if (details.ContainsKey("ErrorType"))
            {
                subject += details["ErrorType"];
            }

            string body = "<table>\n";

            body += String.Join("\n", details.Select(kvp => $"<tr><td>{kvp.Key}</td><td>{kvp.Value}</td></tr>"));
            body += "</table>\n\n";

            if (exc != null)
            {
                body += "<h1>Exception</h1>\n";
                body += ExceptionToHtml(exc);
            }

            var message = new MailMessage(_options.FromAddress, _options.ToAddress, subject, body);

            message.IsBodyHtml = true;
            //TODO what to do with exceptions here?
            await _mailClient.SendMailAsync(message);
        }
コード例 #2
0
        public async Task NotifyAsync(DescriptiveError descriptiveError, Exception unhandledException, string path, ClaimsPrincipal user = null)
        {
            var details = new Dictionary <string, string>()
            {
                { "IsClientSide", "false" },
                { "Path", path },
                { "Descriptive.Message", descriptiveError.Message },
                { "Time", DateTime.UtcNow.ToString("g") }
            };

            await AppendUserAsync(user, details);

            AppendAdditionalDetails(descriptiveError, details);

            await ReportAsync(details, ExceptionToHandle.FromException(unhandledException));
        }
コード例 #3
0
        private string ExceptionToHtml(ExceptionToHandle exc)
        {
            var html = "<table>\n";

            html += $"<tr><td>Type</td><td>{exc.ExceptionType}</td></tr>\n";
            html += $"<tr><td>Message</td><td>{exc.Message}</td></tr>\n";
            html += $"<tr><td>Source</td><td>{exc.Source}</td></tr>\n";
            html += $"<tr><td>Stack</td><td><pre>{exc.StackTrace}</pre></td></tr>\n";

            if (exc.InnerException != null)
            {
                html += $"<tr><td>Inner Exception</td><td>\n{ExceptionToHtml(exc.InnerException)}\n</td></tr>";
            }

            html += "</table>\n";
            return(html);
        }
コード例 #4
0
        public static ExceptionToHandle FromException(Exception exc)
        {
            var eth = new ExceptionToHandle()
            {
                ExceptionType = exc.GetType().Name,
                Message       = exc.Message,
                Source        = exc.Source,
                StackTrace    = exc.StackTrace
            };

            // TODO exception type-specific properties here

            if (exc.InnerException != null)
            {
                eth.InnerException = FromException(exc.InnerException);
            }

            return(eth);
        }