HumaneExceptionErrorType() public static méthode

Formats the error type of an Error object in a short and human-readable form.
public static HumaneExceptionErrorType ( Error error ) : string
error Error
Résultat string
        private static void RenderError(HtmlTextWriter writer, ErrorLogEntry entry, Uri baseUrl)
        {
            Debug.Assert(writer != null);
            Debug.Assert(entry != null);
            Debug.Assert(baseUrl != null);
            Debug.Assert(baseUrl.IsAbsoluteUri);

            var error = entry.Error;

            writer.RenderBeginTag(HtmlTextWriterTag.Li);

            var errorType = ErrorDisplay.HumaneExceptionErrorType(error);

            if (errorType.Length > 0)
            {
                var abbreviated = errorType.Length < error.Type.Length;

                if (abbreviated)
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Title, error.Type);
                    writer.RenderBeginTag(HtmlTextWriterTag.Span);
                }

                HttpUtility.HtmlEncode(errorType, writer);

                if (abbreviated)
                {
                    writer.RenderEndTag(/* span */);
                }

                writer.Write(": ");
            }

            writer.AddAttribute(HtmlTextWriterAttribute.Href, baseUrl + "detail?id=" + HttpUtility.UrlEncode(entry.Id));
            writer.RenderBeginTag(HtmlTextWriterTag.A);
            HttpUtility.HtmlEncode(error.Message, writer);
            writer.RenderEndTag(/* a */);

            writer.RenderEndTag(/* li */);
        }
        private static void RenderError(TextWriter writer, ErrorLogEntry entry, Uri baseUrl)
        {
            Debug.Assert(writer != null);
            Debug.Assert(entry != null);
            Debug.Assert(baseUrl != null);
            Debug.Assert(baseUrl.IsAbsoluteUri);

            var error = entry.Error;

            writer.Write("<li>");

            var errorType = ErrorDisplay.HumaneExceptionErrorType(error);

            if (errorType.Length > 0)
            {
                var abbreviated = errorType.Length < error.Type.Length;

                if (abbreviated)
                {
                    writer.Write("<span title='{0}'>", Html.Encode(error.Type).ToHtmlString());
                }

                writer.Write(Html.Encode(errorType).ToHtmlString());

                if (abbreviated)
                {
                    writer.Write("</span>");
                }

                writer.Write(": ");
            }

            writer.Write("<a href='{0}'>", Html.Encode(baseUrl + "detail?id=" + Uri.EscapeDataString(entry.Id)).ToHtmlString());
            writer.Write(Html.Encode(error.Message).ToHtmlString());
            writer.Write("</a>");

            writer.Write("</li>");
        }
Exemple #3
0
        public override void Execute()
        {
            WriteLiteral("\r\n");



            #line 8 "..\..\ErrorLogPage.cshtml"

            const int defaultPageSize = 15;
            const int maximumPageSize = 100;

            var basePageName = Request.ServerVariables["URL"];

            //
            // Get the page index and size parameters within their bounds.
            //

            var pageSize = Convert.ToInt32(Request.QueryString["size"], CultureInfo.InvariantCulture);
            pageSize = Math.Min(maximumPageSize, Math.Max(0, pageSize));

            if (pageSize == 0)
            {
                pageSize = defaultPageSize;
            }

            var pageIndex = Convert.ToInt32(Request.QueryString["page"], CultureInfo.InvariantCulture);
            pageIndex = Math.Max(1, pageIndex) - 1;

            //
            // Read the error records.
            //

            var log            = this.ErrorLog ?? ErrorLog.GetDefault(Context);
            var errorEntryList = new List <ErrorLogEntry>(pageSize);
            var totalCount     = log.GetErrors(pageIndex, pageSize, errorEntryList);

            //
            // Set the title of the page.
            //

            var hostName = Elmah.Environment.TryGetMachineName(Context);
            var title    = string.Format(
                hostName.Length > 0
        ? "Error log for {0} on {2} (Page #{1})"
        : "Error log for {0} (Page #{1})",
                log.ApplicationName, (pageIndex + 1).ToString("N0"), hostName);

            Layout = new Elmah.MasterPage
            {
                Context       = Context, /* TODO Consider not requiring this */
                Title         = title,
                Footnote      = string.Format("This log is provided by the {0}.", log.Name),
                SpeedBarItems = new[]
                {
                    SpeedBar.RssFeed.Format(basePageName),
                    SpeedBar.RssDigestFeed.Format(basePageName),
                    SpeedBar.DownloadLog.Format(basePageName),
                    SpeedBar.Help,
                    SpeedBar.About.Format(basePageName),
                },
            };

            // If the application name matches the APPL_MD_PATH then its
            // of the form /LM/W3SVC/.../<name>. In this case, use only the
            // <name> part to reduce the noise. The full application name is
            // still made available through a tooltip.

            var simpleName = log.ApplicationName;

            if (string.Compare(simpleName, Request.ServerVariables["APPL_MD_PATH"],
                               true, CultureInfo.InvariantCulture) == 0)
            {
                var lastSlashIndex = simpleName.LastIndexOf('/');

                if (lastSlashIndex > 0)
                {
                    simpleName = simpleName.Substring(lastSlashIndex + 1);
                }
            }



            #line default
            #line hidden
            WriteLiteral("        <h1 id=\"PageTitle\">\r\n            Error Log for <span id=\"ApplicationName\"" +
                         " title=\"");



            #line 82 "..\..\ErrorLogPage.cshtml"
            Write(log.ApplicationName);


            #line default
            #line hidden
            WriteLiteral("\">");



            #line 82 "..\..\ErrorLogPage.cshtml"
            Write(simpleName);


            #line default
            #line hidden
            WriteLiteral(" \r\n");



            #line 83 "..\..\ErrorLogPage.cshtml"
            if (!string.IsNullOrEmpty(hostName))
            {
            #line default
            #line hidden
                WriteLiteral("                ");

                WriteLiteral(" on ");



            #line 85 "..\..\ErrorLogPage.cshtml"
                Write(hostName);


            #line default
            #line hidden
                WriteLiteral(" \r\n");



            #line 86 "..\..\ErrorLogPage.cshtml"
            }


            #line default
            #line hidden
            WriteLiteral("            </span>\r\n        </h1>\r\n        \r\n");



            #line 90 "..\..\ErrorLogPage.cshtml"
            if (errorEntryList.Count > 0)
            {
                // Write error number range displayed on this page and the
                // total available in the log, followed by stock
                // page sizes.

                var firstErrorNumber = pageIndex * pageSize + 1;
                var lastErrorNumber  = firstErrorNumber + errorEntryList.Count - 1;
                var totalPages       = (int)Math.Ceiling((double)totalCount / pageSize);

                // Write out a set of stock page size choices. Note that
                // selecting a stock page size re-starts the log
                // display from the first page to get the right paging.

                var stockSizes =
                    from sizes in new[]
                {
                    new[] { 10, 15, 20, 25, 30, 50, 100, },
                }
                from size in sizes.Index()
                let separator =
                    size.Key + 1 == sizes.Length
                    ? null
                    : size.Key + 2 == sizes.Length
                    ? " or "
                    : ", "
                    select LinkHere(basePageName, HtmlLinkType.Start, size.Value.ToString("N0"), 0, size.Value)
                    + separator;



            #line default
            #line hidden
                WriteLiteral("            <p>Errors ");



            #line 119 "..\..\ErrorLogPage.cshtml"
                Write(firstErrorNumber.ToString("N0"));


            #line default
            #line hidden
                WriteLiteral(" to ");



            #line 119 "..\..\ErrorLogPage.cshtml"
                Write(lastErrorNumber.ToString("N0"));


            #line default
            #line hidden
                WriteLiteral(" \r\n                of total ");



            #line 120 "..\..\ErrorLogPage.cshtml"
                Write(totalCount.ToString("N0"));


            #line default
            #line hidden
                WriteLiteral(" \r\n                (page ");



            #line 121 "..\..\ErrorLogPage.cshtml"
                Write((pageIndex + 1).ToString("N0"));


            #line default
            #line hidden
                WriteLiteral(" of ");



            #line 121 "..\..\ErrorLogPage.cshtml"
                Write(totalPages.ToString("N0"));


            #line default
            #line hidden
                WriteLiteral("). \r\n                Start with ");



            #line 122 "..\..\ErrorLogPage.cshtml"
                Write(Html(stockSizes.ToDelimitedString(string.Empty)));


            #line default
            #line hidden
                WriteLiteral(" errors per page.</p>\r\n");



            #line 123 "..\..\ErrorLogPage.cshtml"

                // Write out the main table to display the errors.



            #line default
            #line hidden
                WriteLiteral(@"            <table id=""ErrorLog"" cellspacing=""0"" style=""border-collapse:collapse;"" class=""table table-condensed table-striped"">
                <tr>
                    <th class=""host-col"" style=""white-space:nowrap;"">Host</th>
                    <th class=""code-col"" style=""white-space:nowrap;"">Code</th>
                    <th class=""type-col"" style=""white-space:nowrap;"">Type</th>
                    <th class=""error-col"" style=""white-space:nowrap;"">Error</th>
                    <th class=""user-col"" style=""white-space:nowrap;"">User</th>
                    <th class=""time-col"" style=""white-space:nowrap;"">When</th>
                </tr>

");



            #line 136 "..\..\ErrorLogPage.cshtml"
                foreach (var error in from item in errorEntryList.Index()
                         let e = item.Value.Error
                                 select new
                {
                    Index = item.Key,
                    item.Value.Id,
                    e.HostName,
                    e.StatusCode,
                    StatusDescription =
                        e.StatusCode > 0
                                          ? HttpWorkerRequest.GetStatusDescription(e.StatusCode)
                                          : null,
                    e.Type,
                    HumaneType = ErrorDisplay.HumaneExceptionErrorType(e),
                    e.Message,
                    e.User,
                    When = FuzzyTime.FormatInEnglish(e.Time),
                    Iso8601Time = e.Time.ToString("o"),
                })
                {
            #line default
            #line hidden
                    WriteLiteral("                <tr class=\"");



            #line 156 "..\..\ErrorLogPage.cshtml"
                    Write(error.Index % 2 == 0 ? "even" : "odd");


            #line default
            #line hidden
                    WriteLiteral("\">\r\n                    \r\n                    <td class=\"host-col\" style=\"white-s" +
                                 "pace:nowrap;\">");



            #line 158 "..\..\ErrorLogPage.cshtml"
                    Write(error.HostName);


            #line default
            #line hidden
                    WriteLiteral("</td>\r\n                    <td class=\"code-col\" style=\"white-space:nowrap;\">\r\n");



            #line 160 "..\..\ErrorLogPage.cshtml"
                    if (!string.IsNullOrEmpty(error.StatusDescription))
                    {
            #line default
            #line hidden
                        WriteLiteral("                            <span title=\"");



            #line 162 "..\..\ErrorLogPage.cshtml"
                        Write(error.StatusDescription);


            #line default
            #line hidden
                        WriteLiteral("\">");



            #line 162 "..\..\ErrorLogPage.cshtml"
                        Write(error.StatusCode);


            #line default
            #line hidden
                        WriteLiteral("</span>\r\n");



            #line 163 "..\..\ErrorLogPage.cshtml"
                    }
                    else if (error.StatusCode != 0)
                    {
            #line default
            #line hidden

            #line 166 "..\..\ErrorLogPage.cshtml"
                        Write(error.StatusCode);


            #line default
            #line hidden

            #line 166 "..\..\ErrorLogPage.cshtml"
                    }


            #line default
            #line hidden
                    WriteLiteral("                    </td>\r\n                    <td class=\"type-col\" style=\"white-" +
                                 "space:nowrap;\"><span title=\"");



            #line 169 "..\..\ErrorLogPage.cshtml"
                    Write(error.Type);


            #line default
            #line hidden
                    WriteLiteral("\">");



            #line 169 "..\..\ErrorLogPage.cshtml"
                    Write(error.HumaneType);


            #line default
            #line hidden
                    WriteLiteral("</span></td>\r\n                    \r\n                    <td class=\"error-col\"><sp" +
                                 "an>");



            #line 171 "..\..\ErrorLogPage.cshtml"
                    Write(error.Message);


            #line default
            #line hidden
                    WriteLiteral("</span> \r\n                        <a href=\"");



            #line 172 "..\..\ErrorLogPage.cshtml"
                    Write(basePageName);


            #line default
            #line hidden
                    WriteLiteral("/detail?id=");



            #line 172 "..\..\ErrorLogPage.cshtml"
                    Write(error.Id);


            #line default
            #line hidden
                    WriteLiteral("\">Details&hellip;</a></td>\r\n                    \r\n                    <td class=\"" +
                                 "user-col\" style=\"white-space:nowrap;\">");



            #line 174 "..\..\ErrorLogPage.cshtml"
                    Write(error.User);


            #line default
            #line hidden
                    WriteLiteral("</td>\r\n                    <td class=\"time-col\" style=\"white-space:nowrap;\"><abbr" +
                                 " title=\"");



            #line 175 "..\..\ErrorLogPage.cshtml"
                    Write(error.Iso8601Time);


            #line default
            #line hidden
                    WriteLiteral("\">");



            #line 175 "..\..\ErrorLogPage.cshtml"
                    Write(error.When);


            #line default
            #line hidden
                    WriteLiteral("</abbr></td>\r\n                </tr>\r\n");



            #line 177 "..\..\ErrorLogPage.cshtml"
                }


            #line default
            #line hidden
                WriteLiteral("            </table>\r\n");



            #line 179 "..\..\ErrorLogPage.cshtml"

                // Write out page navigation links.

                //
                // If not on the last page then render a link to the next page.
                //

                var nextPageIndex = pageIndex + 1;
                var moreErrors    = nextPageIndex * pageSize < totalCount;



            #line default
            #line hidden
                WriteLiteral("            <p>\r\n\r\n");



            #line 191 "..\..\ErrorLogPage.cshtml"
                if (moreErrors)
                {
            #line default
            #line hidden

            #line 193 "..\..\ErrorLogPage.cshtml"
                    Write(LinkHere(basePageName, HtmlLinkType.Next, "Next errors", nextPageIndex, pageSize));


            #line default
            #line hidden

            #line 193 "..\..\ErrorLogPage.cshtml"
                }


            #line default
            #line hidden


            #line 195 "..\..\ErrorLogPage.cshtml"
                if (pageIndex > 0 && totalCount > 0)
                {
                    if (moreErrors)
                    {
                        Write("; ");
                    }


            #line default
            #line hidden

            #line 200 "..\..\ErrorLogPage.cshtml"
                    Write(LinkHere(basePageName, HtmlLinkType.Start, "Back to first page", 0, pageSize));


            #line default
            #line hidden

            #line 200 "..\..\ErrorLogPage.cshtml"
                }


            #line default
            #line hidden
                WriteLiteral("\r\n            </p>\r\n");



            #line 204 "..\..\ErrorLogPage.cshtml"
            }
            else
            {
                // No errors found in the log, so display a corresponding
                // message.

                // It is possible that there are no error at the requested
                // page in the log (especially if it is not the first page).
                // However, if there are error in the log

                if (pageIndex > 0 && totalCount > 0)
                {
            #line default
            #line hidden
                    WriteLiteral("                <p>");



            #line 216 "..\..\ErrorLogPage.cshtml"
                    Write(LinkHere(basePageName, HtmlLinkType.Start, "Go to first page", 0, pageSize));


            #line default
            #line hidden
                    WriteLiteral(".</p>\r\n");



            #line 217 "..\..\ErrorLogPage.cshtml"
                }
                else
                {
            #line default
            #line hidden
                    WriteLiteral("                <p>No errors found.</p>\r\n");



            #line 221 "..\..\ErrorLogPage.cshtml"
                }
            }


            #line default
            #line hidden
            WriteLiteral("\r\n");


            WriteLiteral("\r\n");
        }
Exemple #4
0
        private void RenderErrors(HtmlTextWriter writer)
        {
            Debug.Assert(writer != null);

            //
            // Create a table to display error information in each row.
            //

            Table table = new Table();

            table.ID          = "ErrorLog";
            table.CellSpacing = 0;

            //
            // Create the table row for headings.
            //

            TableRow headRow = new TableRow();

            headRow.Cells.Add(FormatCell(new TableHeaderCell(), "Host", "host-col"));
            headRow.Cells.Add(FormatCell(new TableHeaderCell(), "Code", "code-col"));
            headRow.Cells.Add(FormatCell(new TableHeaderCell(), "Type", "type-col"));
            headRow.Cells.Add(FormatCell(new TableHeaderCell(), "Error", "error-col"));
            headRow.Cells.Add(FormatCell(new TableHeaderCell(), "User", "user-col"));
            headRow.Cells.Add(FormatCell(new TableHeaderCell(), "Date", "date-col"));
            headRow.Cells.Add(FormatCell(new TableHeaderCell(), "Time", "time-col"));

            table.Rows.Add(headRow);

            //
            // Generate a table body row for each error.
            //

            for (int errorIndex = 0; errorIndex < _errorEntryList.Count; errorIndex++)
            {
                ErrorLogEntry errorEntry = (ErrorLogEntry)_errorEntryList[errorIndex];
                Error         error      = errorEntry.Error;

                TableRow bodyRow = new TableRow();
                bodyRow.CssClass = errorIndex % 2 == 0 ? "even-row" : "odd-row";

                //
                // Format host and status code cells.
                //

                bodyRow.Cells.Add(FormatCell(new TableCell(), error.HostName, "host-col"));
                bodyRow.Cells.Add(FormatCell(new TableCell(), error.StatusCode.ToString(), "code-col", Mask.NullString(HttpWorkerRequest.GetStatusDescription(error.StatusCode))));
                bodyRow.Cells.Add(FormatCell(new TableCell(), ErrorDisplay.HumaneExceptionErrorType(error), "type-col", error.Type));

                //
                // Format the message cell, which contains the message
                // text and a details link pointing to the page where
                // all error details can be viewed.
                //

                TableCell messageCell = new TableCell();
                messageCell.CssClass = "error-col";

                Label messageLabel = new Label();
                messageLabel.Text = this.Server.HtmlEncode(error.Message);

                HyperLink detailsLink = new HyperLink();
                detailsLink.NavigateUrl = BasePageName + "/detail?id=" + HttpUtility.UrlEncode(errorEntry.Id);
                detailsLink.Text        = "Details&hellip;";

                messageCell.Controls.Add(messageLabel);
                messageCell.Controls.Add(new LiteralControl(" "));
                messageCell.Controls.Add(detailsLink);

                bodyRow.Cells.Add(messageCell);

                //
                // Format the user, date and time cells.
                //

                bodyRow.Cells.Add(FormatCell(new TableCell(), error.User, "user-col"));
                bodyRow.Cells.Add(FormatCell(new TableCell(), error.Time.ToShortDateString(), "date-col",
                                             error.Time.ToLongDateString()));
                bodyRow.Cells.Add(FormatCell(new TableCell(), error.Time.ToShortTimeString(), "time-col",
                                             error.Time.ToLongTimeString()));

                //
                // Finally, add the row to the table.
                //

                table.Rows.Add(bodyRow);
            }

            table.RenderControl(writer);
        }