Exemplo n.º 1
0
 public void Log(LogEntry entry)
 {
     for (int i = 0; i < loggers.Count; i++) {
         ILogger logger = loggers[i];
         if (loggers != null)
             logger.Log(entry);
     }
 }
Exemplo n.º 2
0
        public void Log(LogEntry entry)
        {
            LogLevel level = entry.Level;
            Type source = Type.GetType(entry.Source);
            string message = String.Format("[{0}] [{1}] ({2}) {3} - {4}", entry.Thread, entry.Level, entry.Time,
                                           (source.Namespace + "." + source.Name), entry.Message);
            TextWriter output = Console.Out;
            if (level >= LogLevel.Error)
                output = Console.Error;

            output.WriteLine(message);
            output.Flush();
        }
Exemplo n.º 3
0
 public void Log(LogEntry entry)
 {
 }
Exemplo n.º 4
0
 private void DoLog(LogEntry entry)
 {
     string threadName = entry.Thread;
     if (String.IsNullOrEmpty(threadName))
         threadName = Thread.CurrentThread.Name;
     BaseLogger.Log(new LogEntry(threadName, entry.Source, entry.Level, entry.Message, entry.Error, entry.Time));
 }
Exemplo n.º 5
0
 public void Log(LogEntry entry)
 {
     if (async) {
         BeginLog(entry, null, null);
     } else {
         DoLog(entry);
     }
 }
Exemplo n.º 6
0
 public IAsyncResult BeginLog(LogEntry entry, AsyncCallback callback, object state)
 {
     return logDelegate.BeginInvoke(entry, callback, state);
 }
Exemplo n.º 7
0
        protected virtual string FormatField(LogEntry entry, string fieldName)
        {
            if (fieldName == null || fieldName.Length == 0)
                return null;

            string format = null;
            int index = fieldName.IndexOf(':');
            if (index != -1) {
                format = fieldName.Substring(index + 1);
                fieldName = fieldName.Substring(0, index);
            }

            if (fieldName.Length == 0)
                return null;

            switch (fieldName.ToLower()) {
                case "message":
                    return (format != null ? String.Format(format, entry.Message) : entry.Message);
                case "time":
                    return (format != null ? entry.Time.ToString(format, CultureInfo.InvariantCulture) : entry.Time.ToString());
                case "source":
                    return (format != null ? String.Format(format, entry.Source) : entry.Source);
                case "level": {
                    if (format != null)
                        format = format.ToLower();
                    if (format == "number" || format == null)
                        return entry.Level.Value.ToString();
                    if (format == "name")
                        return entry.Level.Name;
                    return String.Format(format, entry.Level.Value);
                }
                case "thread": {
                    string threadName = (entry.Thread == null ? Thread.CurrentThread.ManagedThreadId.ToString() : entry.Thread);
                    return (format != null ? String.Format(format, threadName) : threadName);
                }
                default:
                    throw new ArgumentException("Unknown field " + fieldName);
            }
        }
Exemplo n.º 8
0
        protected virtual string FormatEntry(LogEntry entry)
        {
            if (message_format == null || entry == null)
                return String.Empty;

            StringBuilder message = new StringBuilder();
            StringBuilder field = null;

            for (int i = 0; i < message_format.Length; i++) {
                char c = message_format[i];
                if (c == '{') {
                    field = new StringBuilder();
                    continue;
                }
                if (c == '}' && field != null) {
                    string fieldValue = field.ToString();
                    string result = FormatField(entry, fieldValue);
                    message.Append(result);
                    field = null;
                    continue;
                }

                if (field != null) {
                    field.Append(c);
                } else {
                    message.Append(c);
                }
            }

            return message.ToString();
        }
Exemplo n.º 9
0
        public void Log(LogEntry entry)
        {
            lock (output) {
                StringBuilder sb = new StringBuilder();

                if (entry.Level < LogLevel.Message) {
                    sb.Append("> ");
                } else {
                    sb.Append("% ");
                }

                sb.Append(FormatEntry(entry));
                output.WriteLine(sb.ToString());
                output.Flush();
            }
        }