Represents the log event.
        private static bool ParseLog4JEvent(XmlTextReader reader, LogEvent ev)
        {
            ev["Logger"] = reader.GetAttribute("logger");
            ev["Level"] = LogLevelMap.GetLevelForName(reader.GetAttribute("level"));
            ev["Thread"] = reader.GetAttribute("thread");
            ev["Time"] = _log4jDateBase.AddMilliseconds(Convert.ToDouble(reader.GetAttribute("timestamp"))).ToLocalTime();

            // System.Windows.Forms.MessageBox.Show(reader.ReadOuterXml());
            // Log.Write(reader.ReadOuterXml());

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName == "log4j:event")
                        return true;
                }
                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.LocalName)
                    {
                        case "log4j:message":
                            ev["Text"] = reader.ReadString();
                            continue;

                        case "log4j:properties":
                            ParseLog4JProperties(ev, reader, "");
                            continue;

                        case "log4j:MDC":
                            ParseLog4JProperties(ev, reader, "mdc:");
                            continue;

                        default:
                        case "log4j:locationinfo":
                            ev["SourceType"] = reader.GetAttribute("class");
                            ev["SourceMethod"] = reader.GetAttribute("method");
                            ev["SourceFile"] = reader.GetAttribute("file");
                            //ev.SourceLine = reader.GetAttribute("line");
                            continue;

                        case "nlog:locationinfo":
                            ev["SourceAssembly"] = reader.GetAttribute("assembly");
                            break;
                    }
                }
            }

            return true;
        }
示例#2
0
        private ListViewItem LogEventToListViewItem(LogEvent logEvent)
        {
            ListViewItem item = new ListViewItem();
            item.Tag = logEvent;
            item.Text = "";
            foreach (LogColumn lc in _session.Columns)
            {
                if (lc.Visible)
                    item.SubItems.Add(Convert.ToString(logEvent[lc.Name]));
            }
            //item.Font = new Font("Tahoma", SystemInformation.IconSize.Height);
            LogLevel level = logEvent["Level"] as LogLevel;
            if (level != null)
            {
                item.ImageIndex = level.ImageIndex;
                if (level.Color != Color.Empty)
                    item.ForeColor = level.Color;
                if (level.BackColor != Color.Empty)
                    item.BackColor = level.BackColor;
            }
            else
                item.ImageIndex = -1;

            return item;
        }
示例#3
0
        public void LogEventSelected(LogEvent evt)
        {
            textBoxSelectedMessageText.Text = Convert.ToString(evt["Text"]);
            ListViewItem item;

            listviewSelectedLogEventProperties.Items.Clear();

            foreach (LogColumn lc in _session.Columns)
            {
                item = new ListViewItem(new string[] { lc.Name, Convert.ToString(evt[lc.Ordinal]) });
                listviewSelectedLogEventProperties.Items.Add(item);
            }
        }
        private static void ParseLog4JProperties(LogEvent ev, XmlTextReader reader, string namePrefix)
        {
            if (reader.IsEmptyElement)
                return;

            string elementName = reader.LocalName;

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.EndElement && reader.LocalName == elementName)
                {
                    break;
                }
                if (reader.NodeType == XmlNodeType.Element && reader.LocalName == "log4j:data")
                {
                    string name = reader.GetAttribute("name");
                    string value = reader.GetAttribute("value");

                    if (name == "log4japp")
                    {
                        ev["SourceApplication"] = value;
                        continue;
                    }

                    if (name == "log4jmachinename")
                    {
                        ev["SourceMachine"] = value;
                        continue;
                    }

                    ev[namePrefix + name] = value;
                }
            }
        }
 public bool ReadNext(LogEvent logEvent)
 {
     while (_xtr.Read())
     {
         if (_xtr.NodeType == XmlNodeType.Element && _xtr.LocalName == "log4j:event")
         {
             if (ParseLog4JEvent(_xtr, logEvent))
             {
                 return true;
             }
             else
             {
                 return false;
             }
         }
     }
     return false;
 }
            public bool ReadNext(LogEvent le)
            {
                string line = _reader.ReadLine();
                if (line == null)
                    return false;

                Match match = _parser._compiledRegex.Match(line);
                if (!match.Success)
                    return false;

                string[] names = _parser._compiledRegex.GetGroupNames();
                for (int i = 1; i < names.Length; ++i)
                {
                    string v = match.Groups[i].Value;
                    le[names[i]] = v;
                }

                return true;
            }
 public void EventReceived(LogEvent logEvent)
 {
     ILogEventProcessor p = _processor;
     if (p != null)
     {
         p.ProcessLogEvent(logEvent);
     }
 }