Ejemplo n.º 1
0
 /// <summary> Log a message
 ///
 /// </summary>
 /// <param name="level">    log level
 /// </param>
 /// <param name="message">  message to log
 /// </param>
 /// <param name="t">        throwable object
 /// </param>
 public virtual void Log(Level level, string message, Exception t)
 {
     if (globalLevel.IsGreaterOrEqual(level))
     {
         OurLog(level, message, t);
     }
 }
Ejemplo n.º 2
0
 public virtual bool IsEnabledFor(Level level)
 {
     if (globalLevel.IsGreaterOrEqual(level))
     {
         return(true);
     }
     lock (appenders.SyncRoot)
     {
         foreach (Appender appender in appenders)
         {
             if (appender is CustomLogLevelAppender)
             {
                 CustomLogLevelAppender appender2 = (CustomLogLevelAppender)appender;
                 if (appender2.CurrentLevel.IsGreaterOrEqual(level))
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Log a message to our logging system
        /// </summary>
        /// <param name="level">log level</param>
        /// <param name="message">message to log</param>
        /// <param name="t">throwable object</param>
        private void OurLog(Level level, string message, Exception t)
        {
            ts = DateTime.Now;
            string stamp = ts.ToString(format, CultureInfo.CurrentCulture.DateTimeFormat);

            System.Text.StringBuilder buf = new System.Text.StringBuilder(level.ToString());
            if (showClassNames)
            {
                buf.Append(" [");
                buf.Append(clazz);
                buf.Append("]");
            }
            if (showTimestamp)
            {
                buf.Append(" ");
                buf.Append(stamp);
            }
            buf.Append(" : ");
            buf.Append(GetTag());
            string prefix = buf.ToString();

            if (message != null)
            {
                buf.Append(message);
            }
            if (t != null)
            {
                buf.Append(" : ").Append(t.GetType().FullName).Append(": ").Append(t.Message);
            }
            if (appenders.Count == 0)
            {
                // by default to stdout
                System.Console.Out.WriteLine(buf.ToString());
                if (t != null)
                {
                    if (t.StackTrace != null)
                    {
                        foreach (string line in t.StackTrace.Replace("\r", "").Split('\n'))
                        {
                            OurLog(level, prefix + line, null);
                        }
                    }
                    if (t.InnerException != null)
                    {
                        System.Console.Out.WriteLine(
                            string.Format("{0}CAUSED BY - {1}: {2}",
                                          prefix,
                                          t.InnerException.GetType().FullName,
                                          t.InnerException.Message));
                        if (t.InnerException.StackTrace != null)
                        {
                            foreach (string line in t.InnerException.StackTrace.Replace("\r", "").Split('\n'))
                            {
                                OurLog(level, prefix + line, null);
                            }
                        }
                    }
                }
            }
            else
            {
                bool appendToAll = globalLevel.IsGreaterOrEqual(level);
                lock (appenders.SyncRoot)
                {
                    for (int i = 0; i < appenders.Count; i++)
                    {
                        Appender a = (Appender)appenders[i];
                        bool     appendToCustom = false;
                        if (a is CustomLogLevelAppender)
                        {
                            CustomLogLevelAppender appender = (CustomLogLevelAppender)a;
                            appendToCustom = appender.CurrentLevel.IsGreaterOrEqual(level);
                        }
                        if (appendToAll || appendToCustom)
                        {
                            if (message != null)
                            {
                                a.Log(prefix + message);
                            }
                            if (t != null)
                            {
                                a.Log(prefix + t.GetType().FullName + ": " + t.Message);
                                if (t.StackTrace != null)
                                {
                                    foreach (string line in t.StackTrace.Replace("\r", "").Split('\n'))
                                    {
                                        a.Log(prefix + line);
                                    }
                                }
                                if (t.InnerException != null)
                                {
                                    a.Log(prefix + "CAUSED BY - " + t.InnerException.GetType().FullName + ": " + t.Message);
                                    if (t.InnerException.StackTrace != null)
                                    {
                                        foreach (string line in t.InnerException.StackTrace.Replace("\r", "").Split('\n'))
                                        {
                                            a.Log(prefix + line);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }