コード例 #1
0
        /// <summary>
        ///     ¬нутренн¤¤ операци¤ записи в лог
        /// </summary>
        /// <param name="message"> </param>
        protected override void InternalWrite(LoggyMessage message)
        {
            try {
                switch (message.Level)
                {
                case LogLevel.Debug:
                    Console.ForegroundColor = ConsoleColor.DarkGray;
                    break;

                case LogLevel.Trace:
                    Console.ForegroundColor = ConsoleColor.Gray;
                    break;

                case LogLevel.Info:
                    Console.ForegroundColor = ConsoleColor.White;
                    break;

                case LogLevel.Warn:
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    break;

                case LogLevel.Error:
                    Console.ForegroundColor = ConsoleColor.Red;
                    break;

                case LogLevel.Fatal:
                    Console.ForegroundColor = ConsoleColor.Magenta;
                    break;
                }
                Console.WriteLine(GetText(message));
            }
            finally {
                Console.ResetColor();
            }
        }
コード例 #2
0
 public void Write(LoggyMessage message)
 {
     if (!Active)
     {
         return;
     }
     if (IsFor(message.Level))
     {
         if (string.IsNullOrWhiteSpace(message.LoggerName))
         {
             message.LoggerName = this.Name;
         }
         foreach (var appender in Appenders)
         {
             if (appender.Level <= message.Level)
             {
                 appender.Write(message);
             }
         }
         if (HasSubloggers)
         {
             foreach (var subLogger in SubLoggers)
             {
                 if (subLogger.IsFor(message.Level))
                 {
                     subLogger.Write(message);
                 }
             }
         }
     }
 }
コード例 #3
0
ファイル: UdpAppender.cs プロジェクト: Qorpent/qorpent.sys
        protected override void InternalWrite(LoggyMessage message)
        {
            var xml = GetEventXml(message);

            lock (sync) {
                _messageBuffer.Push(xml);
                if (_messageBuffer.Count >= AutoFlushSize)
                {
                    Flush();
                }
            }
        }
コード例 #4
0
ファイル: AppenderBase.cs プロジェクト: Qorpent/qorpent.sys
 public void Write(LoggyMessage message)
 {
     if (!Active)
     {
         return;
     }
     try {
         if (message.Visited.Contains(this.Id))
         {
             return;
         }
         InternalWrite(message);
         message.Visited.Add(this.Id);
     }
     catch (Exception ex) {
         (Manager ?? Loggy.Manager).Get("_failsafe").Error(new{ appendertype = GetType().Name, error = ex.ToString() }.stringify());
     }
 }
コード例 #5
0
ファイル: AppenderBase.cs プロジェクト: Qorpent/qorpent.sys
        protected string GetText(LoggyMessage message)
        {
            if (string.IsNullOrWhiteSpace(message.Message) && null != message.Exception)
            {
                message.Message =
                    message.Exception.GetType().Name + ": " +
                    message.Exception.Message + Environment.NewLine;
                if (null != message.Exception.StackTrace)
                {
                    message.Message +=
                        message.Exception.StackTrace.Substring(0, Math.Min(message.Exception.StackTrace.Length, 200)) + "...";
                }
            }
            var result = message.Message;

            if (!string.IsNullOrWhiteSpace(Format))
            {
                result = Format.Interpolate(message);
            }
            return(result);
        }
コード例 #6
0
        protected override void InternalWrite(LoggyMessage message)
        {
            if (message.Level < Level)
            {
                return;
            }
            object error = null;

            if (null != message.Exception)
            {
                error = new {
                    type    = message.Exception.GetType().Name,
                    message = message.Exception.Message,
                    stack   = message.Exception.StackTrace
                };
            }

            var    id  = GetId(message);
            object mes = message.Message;

            if (message.Message.StartsWith("{") && message.Message.EndsWith("}"))
            {
                mes = message.Message.jsonify();
            }
            var m = new {
                level      = message.Level,
                timestamp  = message.Timestamp.ToUniversalTime(),
                logger     = message.LoggerName,
                loggerpath = "/" + message.LoggerName.Replace(".", "/"),
                message    = mes,
                error,
                user = message.UserName,
                host = Environment.MachineName,
                _id  = id
            };
            var j = m.stringify();

            Client.ExecuteCommand("/" + Index + "/" + Type + "/" + id, j);
        }
コード例 #7
0
ファイル: UdpAppender.cs プロジェクト: Qorpent/qorpent.sys
        public string GetEventXml(LoggyMessage _message)
        {
            var username = "******";

            if (null != PrincipalSource)
            {
                username = PrincipalSource.CurrentUser.Identity.Name;
            }
            else
            {
                if (Applications.Application.HasCurrent)
                {
                    if (Applications.Application.Current.Principal != null)
                    {
                        username = Applications.Application.Current.Principal.CurrentUser.Identity.Name;
                    }
                }
            }
            // The format:
            //<log4j:event logger="{LOGGER}" level="{LEVEL}" thread="{THREAD}" timestamp="{TIMESTAMP}">
            //  <log4j:message><![CDATA[{ERROR}]]></log4j:message>
            //  <log4j:NDC><![CDATA[{MESSAGE}]]></log4j:NDC>
            //  <log4j:throwable><![CDATA[{EXCEPTION}]]></log4j:throwable>
            //  <log4j:locationInfo class="org.apache.log4j.chainsaw.Generator" method="run" file="Generator.java" line="94"/>
            //  <log4j:properties>
            //	<log4j:data name="log4jmachinename" value="{SOURCE}"/>
            //	<log4j:data name="log4japp" value="{APP}"/>
            //  </log4j:properties>
            //</log4j:event>
            var category   = _message.Level.ToString();
            var level      = category;
            var message    = GetText(_message);
            var loggername = _message.LoggerName;


            var builder = new StringBuilder();

            var settings = new XmlWriterSettings();

            settings.OmitXmlDeclaration = true;

            var writer = XmlWriter.Create(builder, settings);

            WriteLog4jElement(writer, "event");
            writer.WriteAttributeString("logger", loggername);
            writer.WriteAttributeString("timestamp", DateTime.Now.ToString("o"));

            writer.WriteAttributeString("level", level);
            writer.WriteAttributeString("thread", Thread.CurrentThread.ManagedThreadId.ToString());
            writer.WriteAttributeString("domain", Environment.MachineName);
            writer.WriteAttributeString("username", username);

            writer.WriteElementString("message", Only30KBytes(RemoveInvalidXmlChars(message)));

            WriteLog4jElement(writer, "properties");
            WriteLog4jElement(writer, "data");
            writer.WriteAttributeString("name", "log4netmachinename");
            writer.WriteAttributeString("value", Environment.MachineName);
            writer.WriteEndElement();


            writer.WriteEndElement();
            if (_message.Exception != null)
            {
                writer.WriteElementString("exception", GetExceptionString(_message.Exception));
            }

            writer.WriteEndElement();

            writer.Flush();
            return(builder.ToString());
        }
コード例 #8
0
 public static void Write(LoggyMessage message)
 {
     Default.Write(message);
 }
コード例 #9
0
 private object GetId(LoggyMessage message)
 {
     return(message.Timestamp.ToUniversalTime().ToString("yyyyMMddHHmmss_") +
            Guid.NewGuid().ToString().GetMd5().Substring(0, 6));
 }
コード例 #10
0
ファイル: AppenderBase.cs プロジェクト: Qorpent/qorpent.sys
 protected abstract void InternalWrite(LoggyMessage message);
コード例 #11
0
 protected override void InternalWrite(LoggyMessage message)
 {
     _output?.WriteLine(GetText(message));
 }