Example #1
0
 /// <summary>
 /// Writes a new message on the console.
 /// </summary>
 /// <param name="msg">The message that has to be processed.</param>
 public override void WriteMessage(LogMessage msg)
 {
     //check for file existance
     if (m_LogFile == null)
     {
         //create the file
         m_LogFile = GetLogFile();
     }
     //log to file
     m_LogFile.WriteLine(msg.ApplyFormat(MessageFormat ?? c_MsgFormat));
     //update message counter
     m_MsgCounter++;
     if (m_MaxFileSize != 0)
     {
         if (((m_MaxFileSize > 0) && (m_MaxFileSize < m_LogFile.BaseStream.Length)) || ((m_MaxFileSize < 0) && (m_MaxFileSize + m_MsgCounter == 0)))
         {
             CloseLogFile();
         }
     }
 }
Example #2
0
        /// <summary>
        /// Writes a new message on the console.
        /// </summary>
        /// <param name="msg">The message that has to be processed.</param>
        public override void WriteMessage(LogMessage msg)
        {
            ConsoleColor original = Console.ForegroundColor;

            switch (msg.Level)
            {
            case LogLevels.Trace:
                Console.ForegroundColor = ConsoleColor.Gray;
                break;

            case LogLevels.Debug:
                Console.ForegroundColor = ConsoleColor.DarkGray;
                break;

            case LogLevels.Info:
                Console.ForegroundColor = ConsoleColor.Cyan;
                break;

            case LogLevels.Success:
                Console.ForegroundColor = ConsoleColor.Green;
                break;

            case LogLevels.Warning:
                Console.ForegroundColor = ConsoleColor.Yellow;
                break;

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

            case LogLevels.Fatal:
                Console.ForegroundColor = ConsoleColor.DarkRed;
                break;
            }
            Console.Write(string.Format("[{0}]:", msg.Level).PadRight(12));
            Console.ForegroundColor = original;
            Console.WriteLine(msg.ApplyFormat(MessageFormat ?? c_MsgFormat));
        }