diff --git a/src/StackExchange.Exceptional.Shared/Internal/ExceptionalSettingsBase.cs b/src/StackExchange.Exceptional.Shared/Internal/ExceptionalSettingsBase.cs index 16ef760f..86c44ae5 100644 --- a/src/StackExchange.Exceptional.Shared/Internal/ExceptionalSettingsBase.cs +++ b/src/StackExchange.Exceptional.Shared/Internal/ExceptionalSettingsBase.cs @@ -99,6 +99,18 @@ public void Register(IErrorNotifier notifier) /// public Action> GetCustomData { get; set; } + /// + /// Method to filter errors. + /// The method takes an `Error` object as input and returns a boolean value indicating whether the object should be filtered. + /// + public Func FilterDataInErrorGrid { get; set; } + + /// + /// Method to get the default columns for a list of strings. + /// The list of strings can be manipulated to remove or add columns. + /// + public Action> GetColumns { get; set; } + /// /// Settings for the rendering of pages. /// diff --git a/src/StackExchange.Exceptional.Shared/Pages/ErrorListPage.cs b/src/StackExchange.Exceptional.Shared/Pages/ErrorListPage.cs index 7def1cb2..81305927 100644 --- a/src/StackExchange.Exceptional.Shared/Pages/ErrorListPage.cs +++ b/src/StackExchange.Exceptional.Shared/Pages/ErrorListPage.cs @@ -1,4 +1,5 @@ using StackExchange.Exceptional.Internal; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -22,7 +23,14 @@ public class ErrorListPage : WebPage public ErrorListPage(ErrorStore store, ExceptionalSettingsBase settings, string baseURL, List errors) : base(null, settings, store, baseURL, "Error Log") { - Errors = errors.OrderByDescending(e => e.LastLogDate ?? e.CreationDate).ToList(); + if (Settings.FilterDataInErrorGrid != null) + { + Errors = errors.Where(settings.FilterDataInErrorGrid).ToList(); + } + else + { + Errors = errors.OrderByDescending(e => e.LastLogDate ?? e.CreationDate).ToList(); + } } /// @@ -64,6 +72,10 @@ protected override void RenderInnerHtml(StringBuilder sb) } else { + var headers = new List() + { + "Type", "Error", "Url", "Remote IP", "Time", "Site", "Server" + }; var last = Errors.FirstOrDefault(); // oh the irony sb.Append("

") .Append("") @@ -77,17 +89,55 @@ protected override void RenderInnerHtml(StringBuilder sb) .AppendLine(@" - - - - - - - - - + "); + + Settings.GetColumns?.Invoke(headers); + + foreach (var header in headers) + { + sb.AppendLine($" "); + } + + var displayLogic = new Dictionary>() + { + { "Type", (e, sb) => sb.Append(" ") }, + { "Error", (e, sb) => { + sb.Append(" "); + } }, + { "Url", (e, sb) => { + sb.Append(" "); + } }, + { "Remote IP", (e, sb) => sb.Append(" ") }, + { "Time", (e, sb) => sb.Append(" ") }, + { "Site", (e, sb) => sb.Append(" ") }, + { "Server", (e, sb) => sb.Append(" ") }, + }; + + sb.AppendLine(@" "); + foreach (var e in Errors) { sb.Append(" ") @@ -101,36 +151,23 @@ protected override void RenderInnerHtml(StringBuilder sb) { sb.Append(" ").Append(IconLock).Append(""); } - sb.AppendLine("") - .Append(" ") - .Append(" ") - .Append(" "); + + foreach (var header in headers) { - sb.Append("") - .Append(e.UrlPath.EncodeTruncateWithEllipsis(40)) - .Append(""); + if (displayLogic.TryGetValue(header, out var displayAction)) + { + displayAction.Invoke(e, sb); + } + else if (e.CustomData != null && e.CustomData.TryGetValue(header, out var customValue)) + { + sb.Append(" "); + } + else + { + sb.Append(" "); + } } - sb.AppendLine("") - .Append(" ") - .Append(" ") - .Append(" ") - .Append(" ") - .AppendLine(" "); } sb.AppendLine(" ") .AppendLine("
TypeErrorUrlRemote IPTimeSiteServer
{header}") + .AppendHtmlEncode(e.Type.ToShortTypeName()) + .AppendLine("").Append(e.Message.HasValue() ? e.Message.EncodeTruncateWithEllipsis(250) : "(no message)").Append(""); + if (e.DuplicateCount > 1) + { + sb.Append(" (") + .Append(e.DuplicateCount.ToString()) + .Append(")"); + } + sb.AppendLine(""); + if (e.UrlPath.HasValue()) + { + sb.Append("") + .Append(e.UrlPath.EncodeTruncateWithEllipsis(40)) + .Append(""); + } + sb.AppendLine("").AppendHtmlEncode(e.IPAddress).AppendLine("") + .AppendHtmlEncode((e.LastLogDate ?? e.CreationDate).ToRelativeTime()) + .AppendLine("").AppendHtmlEncode(e.Host).AppendLine("").AppendHtmlEncode(e.MachineName).AppendLine("
") - .AppendHtmlEncode(e.Type.ToShortTypeName()) - .AppendLine("").Append(e.Message.HasValue() ? e.Message.EncodeTruncateWithEllipsis(250) : "(no message)").Append(""); - if (e.DuplicateCount > 1) - { - sb.Append(" (") - .Append(e.DuplicateCount.ToString()) - .Append(")"); - } - sb.AppendLine(""); - if (e.UrlPath.HasValue()) + sb.AppendLine("").AppendHtmlEncode(customValue).AppendLine("").AppendHtmlEncode(e.IPAddress).AppendLine("") - .AppendHtmlEncode((e.LastLogDate ?? e.CreationDate).ToRelativeTime()) - .AppendLine("").AppendHtmlEncode(e.Host).AppendLine("").AppendHtmlEncode(e.MachineName).AppendLine("
"); @@ -145,4 +182,4 @@ protected override void RenderInnerHtml(StringBuilder sb) } } } -} \ No newline at end of file +}