コード例 #1
0
        /// <summary>
        /// Prints the LogEvent using the StandardOutWriter.
        /// </summary>
        /// <param name="logEvent"></param>
        public static void PrintLogEvent(LogEvent logEvent)
        {
            ConsoleColor?color = null;

            if (UseColors)
            {
                var logLevel = logEvent.LogLevel();
                switch (logLevel)
                {
                case LogLevel.DebugLevel:
                    color = DebugColor;
                    break;

                case LogLevel.InfoLevel:
                    color = InfoColor;
                    break;

                case LogLevel.WarningLevel:
                    color = WarningColor;
                    break;

                case LogLevel.ErrorLevel:
                    color = ErrorColor;
                    break;
                }
            }

            StandardOutWriter.WriteLine(logEvent.ToString(), color);
        }
コード例 #2
0
        /// <summary>
        /// Prints a specified event to the console.
        /// </summary>
        /// <param name="logEvent">The event to print</param>
        public static void PrintLogEvent(LogEvent logEvent)
        {
            try
            {
                ConsoleColor?color = null;

                if (UseColors)
                {
                    var logLevel = logEvent.LogLevel();
                    switch (logLevel)
                    {
                    case LogLevel.DebugLevel:
                        color = DebugColor;
                        break;

                    case LogLevel.InfoLevel:
                        color = InfoColor;
                        break;

                    case LogLevel.WarningLevel:
                        color = WarningColor;
                        break;

                    case LogLevel.ErrorLevel:
                        color = ErrorColor;
                        break;
                    }
                }

                StandardOutWriter.WriteLine(logEvent.ToString(), color);
            }
            catch (FormatException)
            {
                /*
                 * If we've reached this point, the `logEvent` itself is informatted incorrectly.
                 * Therefore we have to treat the data inside the `logEvent` as suspicious and avoid throwing
                 * a second FormatException.
                 */
                var sb = new StringBuilder();
                sb.AppendFormat("[ERROR][{0}][Thread {1}][StandardOutLogger] ", logEvent.Timestamp, 0);
                sb.AppendFormat("Encoutered System.FormatException while recording log: [" +
                                logEvent.LogLevel().PrettyNameFor() + "]")
                .AppendFormat("[" + logEvent.LogSource + "][" + logEvent.Message + "]");

                string msg;
                switch (logEvent.Message)
                {
                case LogMessage formatted:     // a parameterized log
                    msg = "str=[" + formatted.Format + "],args=[" + string.Join(",", formatted.Args) + "]";
                    break;

                case string unformatted:     // pre-formatted or non-parameterized log
                    msg = unformatted;
                    break;

                default:     // surprise!
                    msg = logEvent.Message.ToString();
                    break;
                }

                sb.Append(msg)
                .Append("Please take a look at the logging call where this occurred and fix your format string.");

                StandardOutWriter.WriteLine(sb.ToString(), ErrorColor);
            }
        }
コード例 #3
0
 public void StressTestStandardOutWriter(BenchmarkContext context)
 {
     StandardOutWriter.WriteLine(InputStr, ConsoleColor.Black, ConsoleColor.DarkGreen);
     _consoleWriteThroughputCounter.Increment();
 }
コード例 #4
0
 protected override void ErrorInternal(Error message)
 {
     StandardOutWriter.WriteLine(message.ToString(), ErrorColor);
 }
コード例 #5
0
 protected override void WarningInternal(Warning message)
 {
     StandardOutWriter.WriteLine(message.ToString(), WarningColor);
 }
コード例 #6
0
 protected override void InfoInternal(Info message)
 {
     StandardOutWriter.WriteLine(message.ToString(), InfoColor);
 }
コード例 #7
0
 protected override void DebugInternal(Debug message)
 {
     StandardOutWriter.WriteLine(message.ToString(), DebugColor);
 }
コード例 #8
0
ファイル: ConsoleLogger.cs プロジェクト: tjaskula/akka.net
 public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
 {
     StandardOutWriter.WriteLine($"[{_name}][{logLevel}]{formatter(state, exception)}");
 }