コード例 #1
0
 /// <inheritdoc/>
 public void Log(EncogLogging.LogLevel level, Exception t)
 {
     Log(level, t.ToString());
 }
コード例 #2
0
        /// <summary>
        /// Log the message.
        /// </summary>
        ///
        /// <param name="level">The logging level.</param>
        /// <param name="message">The logging message.</param>
        public void Log(EncogLogging.LogLevel level, String message)
        {
            if (level.CompareTo(currentLevel) > 0)
            {
                DateTime now = DateTime.Now;
                var line = new StringBuilder();
                line.Append(now.ToString());
                line.Append(" [");
                //switch (level)
                //{
                //    case EncogLogLevel.Critical:
                //        line.Append("CRITICAL");
                //        break;
                //    case EncogLogging.LevelError:
                //        line.Append("ERROR");
                //        break;
                //    case EncogLogging.LogLevel.Info:
                //        line.Append("INFO");
                //        break;
                //    case EncogLogging.LogLevel.Debug:
                //        line.Append("DEBUG");
                //        break;
                //    default:
                //        line.Append("?");
                //        break;
                //}
                switch (level)
                {
                    case EncogLogging.LogLevel.None:
                        //Lets do nothing as we will not log.
                        break;
                    case EncogLogging.LogLevel.Trace:
                        line.Append("TRACE");
                        break;
                    case EncogLogging.LogLevel.Debug:
                        line.Append("DEBUG");
                        break;
                    case EncogLogging.LogLevel.Info:
                        line.Append("INFO");
                        break;
                    case EncogLogging.LogLevel.Warn:
                        line.Append("WARN");
                        break;
                    case EncogLogging.LogLevel.Error:
                        line.Append("ERROR");
                        break;
                    case EncogLogging.LogLevel.Critical:
                        line.Append("CRITICAL");
                        break;
                }
                line.Append("][");
                line.Append(Thread.CurrentThread.Name);
                line.Append("]: ");
                line.Append(message);

                if (logConsole)
                {
                    if (currentLevel == EncogLogging.LogLevel.Error)
                        Console.Error.WriteLine(line.ToString());
                    //if (currentLevel.CompareTo(EncogLogging.LogLevel.Error) > 0)
                    //{
                    //    Console.Error.WriteLine(line.ToString());
                    //}
                    else
                    {
                        Console.Out.WriteLine(line.ToString());
                    }
                }
                System.Diagnostics.Debug.WriteLine(line);
            }
        }