Ejemplo n.º 1
0
    private void BuildLogTable(LogEntry[] entries)
    {
        XElement table = new XElement("table");

            XElement tableHeader = new XElement("tr");
            tableHeader.Add(
                    new XElement("th", " "),
                    new XElement("th", StringResourceSystemFacade.GetString("Composite.Management","ServerLog.LogEntry.DateLabel")),
                    new XElement("th", StringResourceSystemFacade.GetString("Composite.Management","ServerLog.LogEntry.MessageLabel")),
                    new XElement("th", StringResourceSystemFacade.GetString("Composite.Management","ServerLog.LogEntry.TitleLabel")),
                    new XElement("th", StringResourceSystemFacade.GetString("Composite.Management","ServerLog.LogEntry.EventTypeLabel"))
                    //new XElement("th", "URL"),
                    //new XElement("th", "Referer")
                );

            table.Add(tableHeader);

            foreach (LogEntry logEntry in entries.Reverse())
            {
                TraceEventType eventType;

                try
                {
                    eventType = (TraceEventType)Enum.Parse(typeof(TraceEventType), logEntry.Severity);
                }
                catch (Exception)
                {
                    eventType = TraceEventType.Information;
                }

                XAttribute color = null;

                switch (eventType)
                {
                    case TraceEventType.Information:
                        color = new XAttribute("bgcolor", "lime");
                        break;

                    case TraceEventType.Verbose:
                        color = new XAttribute("bgcolor", "white");
                        break;

                    case TraceEventType.Warning:
                        color = new XAttribute("bgcolor", "yellow");
                        break;

                    case TraceEventType.Error:
                        color = new XAttribute("bgcolor", "orange");
                        break;

                    case TraceEventType.Critical:
                        color = new XAttribute("bgcolor", "red");
                        break;

                    default:
                        color = new XAttribute("bgcolor", "pink");
                        break;
                }

                XElement row = new XElement("tr");
                row.Add(
                    new XElement("td", " ", color),
                    new XElement("td", string.Format("{0} {1}", logEntry.TimeStamp.ToShortDateString(), logEntry.TimeStamp.ToShortTimeString())),
                    new XElement("td", new XElement("pre", logEntry.Message.Replace("\n", ""))),
                    new XElement("td", logEntry.Title),
                    new XElement("td", logEntry.Severity)
                    //new XElement("td", logEntry.HttpRequestUrl ?? "" + " "),
                    //new XElement("td", logEntry.HttpReferingUrl ?? "" + " ")
                );

                table.Add(row);
            }

            LogHolder.Controls.Add(new LiteralControl(table.ToString()));
    }
Ejemplo n.º 2
0
    private void BuildLogTable(LogEntry[] entries)
    {
        XElement table = new XElement("table");

        XElement tableHeader = new XElement("tr");
        tableHeader.Add(
                new XElement("th", " "),
                new XElement("th", StringResourceSystemFacade.GetString("Composite.Management","ServerLog.LogEntry.DateLabel")),
                new XElement("th", StringResourceSystemFacade.GetString("Composite.Management","ServerLog.LogEntry.MessageLabel")),
                new XElement("th", StringResourceSystemFacade.GetString("Composite.Management","ServerLog.LogEntry.TitleLabel")),
                new XElement("th", StringResourceSystemFacade.GetString("Composite.Management","ServerLog.LogEntry.EventTypeLabel"))
            );

        table.Add(tableHeader);

        foreach (LogEntry logEntry in entries.Reverse())
        {
            TraceEventType eventType;

            try
            {
                eventType = (TraceEventType)Enum.Parse(typeof(TraceEventType), logEntry.Severity);
            }
            catch (Exception)
            {
                eventType = TraceEventType.Information;
            }

            var colors = new []
                               {
                                   new Tuple<TraceEventType, string>(TraceEventType.Information, "lime"),
                                   new Tuple<TraceEventType, string>(TraceEventType.Verbose, "white"),
                                   new Tuple<TraceEventType, string>(TraceEventType.Warning, "yellow"),
                                   new Tuple<TraceEventType, string>(TraceEventType.Error, "orange"),
                                   new Tuple<TraceEventType, string>(TraceEventType.Critical, "red")
                               };

            string colorName = colors.Where(c => c.Item1 == eventType).Select(c => c.Item2).FirstOrDefault() ?? "orange";

            XAttribute color = new XAttribute("bgcolor", colorName);

            XElement row = new XElement("tr");
            row.Add(
                new XElement("td", color, " "),
                new XElement("td", logEntry.TimeStamp.ToString(View_DateTimeFormat)),
                new XElement("td", new XElement("pre", EncodeXml10InvalidCharacters(logEntry.Message.Replace("\n", "")))),
                new XElement("td", EncodeXml10InvalidCharacters(logEntry.Title)),
                new XElement("td", logEntry.Severity)
            );

            table.Add(row);
        }

        LogHolder.Controls.Add(new LiteralControl(table.ToString()));
    }