Beispiel #1
0
        private static void UpcodeToLog(XmlReader reader, List <ElmahLogMessageEntry> log)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }
            if (log == null)
            {
                throw new ArgumentNullException(nameof(log));
            }

            Debug.Assert(!reader.IsEmptyElement);
            reader.Read();

            //
            // Add entries into the collection as <item> elements
            // with child <value> elements are found.
            //
            DateTime LoadTime(string text) =>
            text.Length == 0
                    ? new DateTime()
                    : XmlConvert.ToDateTime(text, XmlDateTimeSerializationMode.Local);

            while (reader.NodeType != XmlNodeType.EndElement)
            {
                if (reader.IsStartElement("message"))
                {
                    var entry = new ElmahLogMessageEntry
                    {
                        Level     = GetLogLevel(reader.GetAttribute("level")),
                        Exception = reader.GetAttribute("exception"),
                        TimeStamp = LoadTime(reader.GetAttribute("time-stamp") ?? string.Empty),
                        Scope     = reader.GetAttribute("scope"),
                        Message   = reader.GetAttribute("message")
                    };

                    log.Add(entry);

                    reader.Read(); // <item>
                }
                else
                {
                    reader.Skip();
                }

                reader.MoveToContent();
            }

            reader.ReadEndElement();
        }
Beispiel #2
0
        private static void UpcodeToLog(XmlReader reader, List <ElmahLogMessageEntry> log)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }
            if (log == null)
            {
                throw new ArgumentNullException(nameof(log));
            }

            Debug.Assert(!reader.IsEmptyElement);
            reader.Read();

            while (reader.NodeType != XmlNodeType.EndElement)
            {
                if (reader.IsStartElement("message"))
                {
                    var entry = new ElmahLogMessageEntry
                    {
                        Level     = GetLogLevel(reader.GetAttribute("level")),
                        Exception = reader.GetAttribute("exception"),
                        TimeStamp = LoadTime(reader.GetAttribute("time-stamp") ?? string.Empty),
                        Scope     = reader.GetAttribute("scope"),
                        Message   = reader.GetAttribute("message")
                    };

                    log.Add(entry);

                    reader.Read(); // <item>
                }
                else
                {
                    reader.Skip();
                }

                reader.MoveToContent();
            }

            reader.ReadEndElement();
        }
Beispiel #3
0
 public void AddMessage(ElmahLogMessageEntry entry)
 {
     Log.Add(entry);
 }