예제 #1
0
파일: LogServer.cs 프로젝트: wpoch/Alcatraz
        private void AddLogMessage(LogMessage logMsg)
        {
            if (_log.IsDebugEnabled) _log.Debug(logMsg);

            //Store the log
            using (var session = _documentStore.OpenSession())
            {
                session.Store(logMsg);
                session.SaveChanges();
            }

            //Broadcast the log to the clients
            _clients.received(logMsg);
        }
예제 #2
0
        /// <summary>
        /// Here we expect the log event to use the log4j schema.
        /// Sample:
        ///     <log4j:event logger="Statyk7.Another.Name.DummyManager" timestamp="1184286222308" level="ERROR" thread="1">
        ///         <log4j:message>This is an Message</log4j:message>
        ///         <log4j:properties>
        ///             <log4j:data name="log4jmachinename" value="remserver" />
        ///             <log4j:data name="log4net:HostName" value="remserver" />
        ///             <log4j:data name="log4net:UserName" value="REMSERVER\Statyk7" />
        ///             <log4j:data name="log4japp" value="Test.exe" />
        ///         </log4j:properties>
        ///     </log4j:event>
        /// </summary>
        /// 
        /// Implementation inspired from: http://geekswithblogs.net/kobush/archive/2006/04/20/75717.aspx
        /// 
        public static LogMessage ParseLog4JXmlLogEvent(XmlReader reader, string defaultLogger)
        {
            var logMsg = new LogMessage();

            reader.Read();
            if ((reader.MoveToContent() != XmlNodeType.Element) || (reader.Name != "log4j:event"))
                throw new Exception("The Log Event is not a valid log4j Xml block.");

            logMsg.LoggerName = reader.GetAttribute("logger");
            logMsg.Level = EnumExtensions.Parse<LogLevel>(reader.GetAttribute("level"));
            logMsg.ThreadName = reader.GetAttribute("thread");

            long timeStamp;
            if (long.TryParse(reader.GetAttribute("timestamp"), out timeStamp))
                logMsg.TimeStamp = s1970.AddMilliseconds(timeStamp).ToLocalTime();

            int eventDepth = reader.Depth;
            reader.Read();
            while (reader.Depth > eventDepth)
            {
                if (reader.MoveToContent() == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                        case "log4j:message":
                            logMsg.Message = reader.ReadString();
                            break;

                        case "log4j:throwable":
                            logMsg.Message += Environment.NewLine + reader.ReadString();
                            break;

                        case "log4j:locationInfo":
                            break;

                        case "log4j:properties":
                            reader.Read();
                            while (reader.MoveToContent() == XmlNodeType.Element
                                   && reader.Name == "log4j:data")
                            {
                                string name = reader.GetAttribute("name");
                                string value = reader.GetAttribute("value");
                                logMsg.Properties[name] = value;
                                reader.Read();
                            }
                            break;
                    }
                }
                reader.Read();
            }

            return logMsg;
        }