示例#1
0
        /// <summary>
        /// Outputs the message to the console, with the specified foreground
        /// </summary>
        /// <param name="message"></param>
        public void WriteToConsole(LogInformation message)
        {
            switch (message.Type)
            {
            case LogMessageType.INFO:
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine(message.Message);
                Console.ResetColor();
                break;

            case LogMessageType.ERROR:
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(message.Message);
                Console.ResetColor();
                break;

            case LogMessageType.WARNING:
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(message.Message);
                Console.ResetColor();
                break;

            default:
                Console.WriteLine(message.Message);
                break;
            }
        }
示例#2
0
        private LogInformation LogTheMessage(string message, Type loggedFromThisClassType, LogMessageType type)
        {
            lock (_lock)
            {
                LogInformation logInformation = null;

                switch (type)
                {
                case LogMessageType.WARNING:
                    logInformation = new LogInformation
                    {
                        Message = DateTime.Now + " WARNING " + loggedFromThisClassType.FullName + " - " + message,
                        Type    = LogMessageType.WARNING
                    };
                    break;

                case LogMessageType.ERROR:
                    logInformation = new LogInformation
                    {
                        Message = DateTime.Now + " ERROR " + loggedFromThisClassType.FullName + " - " + message,
                        Type    = LogMessageType.ERROR
                    };
                    break;

                case LogMessageType.INFO:
                    logInformation = new LogInformation
                    {
                        Message = DateTime.Now + " INFO " + loggedFromThisClassType.FullName + " - " + message,
                        Type    = LogMessageType.INFO
                    };
                    break;

                case LogMessageType.FATAL:
                    logInformation = new LogInformation
                    {
                        Message = DateTime.Now + " FATAL " + loggedFromThisClassType.FullName + " - " + message,
                        Type    = LogMessageType.FATAL
                    };
                    break;

                case LogMessageType.FINALINFO:
                    logInformation = new LogInformation
                    {
                        Message = DateTime.Now + " FINALINFO " + loggedFromThisClassType.FullName + " - " + message,
                        Type    = LogMessageType.FINALINFO
                    };
                    break;

                case LogMessageType.CANCELINFO:
                    logInformation = new LogInformation
                    {
                        Message = DateTime.Now + " CANCELINFO " + loggedFromThisClassType.FullName + " - " + message,
                        Type    = LogMessageType.CANCELINFO
                    };
                    break;
                }

                File.AppendAllText(_path, logInformation.Message + Environment.NewLine);

                if (LogToConsoleEnabled)
                {
                    WriteToConsole(logInformation);
                }

                return(logInformation);
            }
        }