public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/xml";

            // Get the last set of errors for this application.
            const int pageSize       = 15;
            ArrayList errorEntryList = new ArrayList(pageSize);

            ErrorLog.Default.GetErrors(0, pageSize, errorEntryList);

            // We'll be emitting RSS vesion 0.91.
            RichSiteSummary rss = new RichSiteSummary();

            rss.version = "0.91";

            // Set up the RSS channel.
            Channel channel = new Channel();

            channel.title       = "Error log of " + ErrorLog.Default.ApplicationName + " on " + Environment.MachineName;
            channel.description = "Log of recent errors";
            channel.language    = "en";
            channel.link        = context.Request.Url.GetLeftPart(UriPartial.Authority) +
                                  context.Request.ServerVariables["URL"];
            rss.channel = channel;

            // For each error, build a simple channel item.
            // Only the title, description, link and pubDate fields are populated.
            channel.item = new Item[errorEntryList.Count];

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

                Item item = new Item();

                item.title       = error.Message;
                item.description = "An error of type " + error.Type + " occurred. " + error.Message;
                item.link        = channel.link + "/detail?id=" + errorEntry.Id;
                item.pubDate     = error.Time.ToUniversalTime().ToString("r");

                channel.item[index] = item;
            }

            XmlSerializer serializer = new XmlSerializer(typeof(RichSiteSummary));

            serializer.Serialize(context.Response.Output, rss);
        }
Esempio n. 2
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/xml";

            //
            // Get the last set of errors for this application.
            //

            const int            pageSize       = 15;
            List <ErrorLogEntry> errorEntryList = new List <ErrorLogEntry>(pageSize);
            ErrorLog             log            = ErrorLog.GetDefault(context);

            log.GetErrors(0, pageSize, errorEntryList);

            //
            // We'll be emitting RSS vesion 0.91.
            //

            RichSiteSummary rss = new RichSiteSummary();

            rss.version = "0.91";

            //
            // Set up the RSS channel.
            //

            Channel channel  = new Channel();
            string  hostName = Environment.TryGetMachineName(context);

            channel.title = "Error log of " + log.ApplicationName
                            + (hostName.Length > 0 ? " on " + hostName : null);
            channel.description = "Log of recent errors";
            channel.language    = "en";
            channel.link        = context.Request.Url.GetLeftPart(UriPartial.Authority) +
                                  context.Request.ServerVariables["URL"];

            rss.channel = channel;

            //
            // For each error, build a simple channel item. Only the title,
            // description, link and pubDate fields are populated.
            //

            channel.item = new Item[errorEntryList.Count];

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

                Item item = new Item();

                item.title       = error.Message;
                item.description = "An error of type " + error.Type + " occurred. " + error.Message;
                item.link        = channel.link + "/detail?id=" + HttpUtility.UrlEncode(errorEntry.Id);
                item.pubDate     = error.Time.ToUniversalTime().ToString("r");

                channel.item[index] = item;
            }

            //
            // Stream out the RSS XML.
            //

            context.Response.Write(XmlText.StripIllegalXmlCharacters(XmlSerializer.Serialize(rss)));
        }
Esempio n. 3
0
        private void Render()
        {
            Response.ContentType = "application/xml";

            ErrorLog log = ErrorLog.GetDefault(_context);

            //
            // We'll be emitting RSS vesion 0.91.
            //

            RichSiteSummary rss = new RichSiteSummary();

            rss.version = "0.91";

            //
            // Set up the RSS channel.
            //

            Channel channel  = new Channel();
            string  hostName = Environment.TryGetMachineName(_context);

            channel.title = "Daily digest of errors in "
                            + log.ApplicationName
                            + (hostName.Length > 0 ? " on " + hostName : null);
            channel.description = "Daily digest of application errors";
            channel.language    = "en";

            Uri baseUrl = new Uri(ErrorLogPageFactory.GetRequestUrl(_context).GetLeftPart(UriPartial.Authority) + Request.ServerVariables["URL"]);

            channel.link = baseUrl.ToString();

            rss.channel = channel;

            //
            // Build the channel items.
            //

            const int pageSize       = 30;
            const int maxPageLimit   = 30;
            ArrayList itemList       = new ArrayList(pageSize);
            ArrayList errorEntryList = new ArrayList(pageSize);

            //
            // Start with the first page of errors.
            //

            int pageIndex = 0;

            //
            // Initialize the running state.
            //

            DateTime       runningDay        = DateTime.MaxValue;
            int            runningErrorCount = 0;
            Item           item   = null;
            StringBuilder  sb     = new StringBuilder();
            HtmlTextWriter writer = new HtmlTextWriter(new StringWriter(sb));

            do
            {
                //
                // Get a logical page of recent errors and loop through them.
                //

                errorEntryList.Clear();
                log.GetErrors(pageIndex++, pageSize, errorEntryList);

                foreach (ErrorLogEntry entry in errorEntryList)
                {
                    Error    error = entry.Error;
                    DateTime time  = error.Time.ToUniversalTime();
                    DateTime day   = new DateTime(time.Year, time.Month, time.Day);

                    //
                    // 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);
                            item.description = sb.ToString();
                            itemList.Add(item);
                        }

                        runningDay        = day;
                        runningErrorCount = 0;

                        if (itemList.Count == pageSize)
                        {
                            break;
                        }

                        item         = new Item();
                        item.pubDate = time.ToString("r");
                        item.title   = string.Format("Digest for {0} ({1})",
                                                     runningDay.ToString("yyyy-MM-dd"), runningDay.ToLongDateString());

                        sb.Length = 0;
                        RenderStart(writer);
                    }

                    RenderError(writer, entry, baseUrl);
                    runningErrorCount++;
                }
            }while (pageIndex < maxPageLimit && itemList.Count < pageSize && errorEntryList.Count > 0);

            if (runningErrorCount > 0)
            {
                RenderEnd(writer);
                item.description = sb.ToString();
                itemList.Add(item);
            }

            channel.item = (Item[])itemList.ToArray(typeof(Item));

            //
            // Stream out the RSS XML.
            //

            Response.Write(XmlText.StripIllegalXmlCharacters(XmlSerializer.Serialize(rss)));
        }