Esempio n. 1
0
        private static IAppender GetConsoleAppender(ILayout layout)
        {
            #if WINDOWS
            ConsoleAppender appender = new ConsoleAppender ();
            appender.Layout = layout;
            return appender;
            #else
            AnsiColorTerminalAppender appender = new AnsiColorTerminalAppender ();
            appender.Layout = layout;

            // error = red
            AnsiColorTerminalAppender.LevelColors colors = new AnsiColorTerminalAppender.LevelColors ();
            colors.ForeColor = AnsiColorTerminalAppender.AnsiColor.Red;
            colors.Level = Level.Error;
            appender.AddMapping (colors);

            // warning = yellow
            colors = new AnsiColorTerminalAppender.LevelColors ();
            colors.ForeColor = AnsiColorTerminalAppender.AnsiColor.Yellow;
            colors.Attributes = AnsiColorTerminalAppender.AnsiAttributes.Bright;
            colors.Level = Level.Warn;
            appender.AddMapping (colors);

            appender.ActivateOptions ();
            return appender;
            #endif
        }
Esempio n. 2
0
        /// <summary>
        /// Creates the console appender according options.
        /// </summary>
        /// <returns>The created console appender.</returns>
        /// <param name="logOptions">The log options.</param>
        private static IAppender CreateColoredConsoleAppender(ILogOptions logOptions)
        {
            var appender = new AnsiColorTerminalAppender();
            var pl = new PatternLayout();
            pl.ConversionPattern = logOptions.LogPattern;
            pl.ActivateOptions();
            appender.Layout = pl;
            appender.ActivateOptions();

            appender.AddMapping(new AnsiColorTerminalAppender.LevelColors() { Level = Level.Trace, ForeColor = AnsiColorTerminalAppender.AnsiColor.Blue });
            appender.AddMapping(new AnsiColorTerminalAppender.LevelColors() { Level = Level.Debug, ForeColor = AnsiColorTerminalAppender.AnsiColor.White });
            appender.AddMapping(new AnsiColorTerminalAppender.LevelColors() { Level = Level.Info, ForeColor = AnsiColorTerminalAppender.AnsiColor.Green });
            appender.AddMapping(new AnsiColorTerminalAppender.LevelColors() { Level = Level.Warn, ForeColor = AnsiColorTerminalAppender.AnsiColor.Yellow });
            appender.AddMapping(new AnsiColorTerminalAppender.LevelColors() { Level = Level.Error, ForeColor = AnsiColorTerminalAppender.AnsiColor.Red });
            appender.AddMapping(new AnsiColorTerminalAppender.LevelColors() { Level = Level.Fatal, BackColor = AnsiColorTerminalAppender.AnsiColor.Red, ForeColor = AnsiColorTerminalAppender.AnsiColor.White });

            return appender;
        }