Exemplo n.º 1
0
        /// <summary>
        /// Enqueue to be written
        /// </summary>
        /// <param name="entry"></param>
        /// <remarks>
        /// The entry might be written directly in the same thread or enqueued to be written
        /// later. It's up to each implementation to decide. Keep in mind that a logger should not
        /// introduce delays in the thread execution. If it's possible that it will delay the thread,
        /// enqueue entries instead and write them in a seperate thread.
        /// </remarks>
        public void Enqueue(LogEntry entry)
        {
            string method = entry.StackFrameOrType();

            string tmp = String.Format("{0} {1} {2} {3} {4}",
                                       entry.CreatedAt.ToString("yyyy-MM-dd HH:mm:ss.fff"),
                                       entry.ThreadId.ToString().PadLeft(3),
                                       entry.UserName.PadRight(25),
                                       method.PadRight(40),
                                       entry.Message.Replace("\r\n", "\r\n\t"));

            Console.ForegroundColor = GetColor(entry);
            Console.WriteLine(tmp);
            if (entry.Exception != null)
            {
                Exception exception = entry.Exception;
                string tabs = "\t";
                while (exception != null)
                {
                    Console.WriteLine(tabs + entry.Exception.ToString().Replace("\r\n", "\r\n" + tabs));

                    exception = exception.InnerException;
                    tabs += "\t";
                }
            }
            Console.ForegroundColor = ConsoleColor.Gray;
        }