Exemple #1
0
        public static void ProcessRequest(HttpContextBase context)
        {
            const int pageSize = 15;
            var       entries  = new List <ErrorLogEntry>(pageSize);
            var       log      = ErrorLog.GetDefault(context);

            log.GetErrors(0, pageSize, entries);

            var response = context.Response;

            response.ContentType = "application/xml";

            var title = string.Format(@"Error log of {0} on {1}",
                                      log.ApplicationName, Environment.MachineName);

            var link    = ErrorLogPageFactory.GetRequestUrl(context).GetLeftPart(UriPartial.Authority) + context.Request.ServerVariables["URL"];
            var baseUrl = new Uri(link.TrimEnd('/') + "/");

            var items =
                from entry in entries
                let error = entry.Error
                            select RssXml.Item(
                    error.Message,
                    "An error of type " + error.Type + " occurred. " + error.Message,
                    error.Time,
                    baseUrl + "detail?id=" + Uri.EscapeDataString(entry.Id));

            var rss = RssXml.Rss(title, link, "Log of recent errors", items);

            response.Write(XmlText.StripIllegalXmlCharacters(rss.ToString()));
        }
        private static IEnumerable <XElement> GetItems(ErrorLog log, Uri baseUrl, int pageSize, int maxPageLimit)
        {
            Debug.Assert(log != null);
            Debug.Assert(baseUrl != null);
            Debug.Assert(baseUrl.IsAbsoluteUri);
            Debug.Assert(pageSize > 0);

            var      runningDay        = DateTime.MaxValue;
            var      runningErrorCount = 0;
            string   title             = null;
            DateTime?pubDate           = null;
            var      sb     = new StringBuilder();
            var      writer = new HtmlTextWriter(new StringWriter(sb));

            var source = GetErrors(log, pageSize, (p, e) => new { PageIndex = p, Entry = e });

            foreach (var entry in from item in source.TakeWhile(e => e.PageIndex < maxPageLimit)
                     select item.Entry)
            {
                var error = entry.Error;
                var time  = error.Time.ToUniversalTime();
                var day   = time.Date;

                //
                // If we're dealing with a new day then break out to a
                // new channel item, finishing off the previous one.
                //

                if (day < runningDay)
                {
                    if (runningErrorCount > 0)
                    {
                        RenderEnd(writer);
                        Debug.Assert(title != null);
                        Debug.Assert(pubDate != null);
                        yield return(RssXml.Item(title, sb.ToString(), pubDate.Value));
                    }

                    runningDay        = day;
                    runningErrorCount = 0;
                    pubDate           = time;
                    title             = string.Format("Digest for {0} ({1})", runningDay.ToString("yyyy-MM-dd"), runningDay.ToLongDateString());
                    sb.Length         = 0;
                    RenderStart(writer);
                }

                RenderError(writer, entry, baseUrl);
                runningErrorCount++;
            }

            if (runningErrorCount > 0)
            {
                RenderEnd(writer);
                Debug.Assert(title != null);
                Debug.Assert(pubDate != null);
                yield return(RssXml.Item(title, sb.ToString(), pubDate.Value));
            }
        }
        public static void ProcessRequest(HttpContextBase context)
        {
            var log = ErrorLog.GetDefault(context);

            var request  = context.Request;
            var response = context.Response;

            response.ContentType = "application/xml";

            var title = string.Format(@"Daily digest of errors in {0} on {1}",
                                      log.ApplicationName, Environment.MachineName);

            var link    = ErrorLogPageFactory.GetRequestUrl(context).GetLeftPart(UriPartial.Authority) + request.ServerVariables["URL"];
            var baseUrl = new Uri(link.TrimEnd('/') + "/");

            var items = GetItems(log, baseUrl, 30, 30).Take(30);
            var rss   = RssXml.Rss(title, link, "Daily digest of application errors", items);

            context.Response.Write(XmlText.StripIllegalXmlCharacters(rss.ToString()));
        }