Sha256: 53b3d670614147b582a5c035b6803639ad1504e718de8c8193fb7322a2a7957d

Contents?: true

Size: 1.8 KB

Versions: 3

Compression:

Stored size: 1.8 KB

Contents

using NLog;
using NLog.Win32.Targets;

class Example
{
    static void Main(string[] args)
    {
        ColoredConsoleTarget target = new ColoredConsoleTarget();
        target.Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}";
        target.RowHighlightingRules.Add(
                new ConsoleRowHighlightingRule(
                    "level >= LogLevel.Error and contains(message,'serious')", // condition
                    ConsoleOutputColor.White, // foreground color
                    ConsoleOutputColor.Red // background color
                    )
                );

        target.RowHighlightingRules.Add(
                new ConsoleRowHighlightingRule(
                    "starts-with(logger,'Example')", // condition
                    ConsoleOutputColor.Yellow, // foreground color
                    ConsoleOutputColor.DarkBlue) // background color
                );
        NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Trace);

        // LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration("ColoredConsoleTargetRowHighlighting.nlog");

        Logger logger = LogManager.GetLogger("Example");
        logger.Trace("trace log message");
        logger.Debug("debug log message");
        logger.Info("info log message");
        logger.Warn("warn log message");
        logger.Error("very serious error log message");
        logger.Fatal("fatal log message, rather serious");

        Logger logger2 = LogManager.GetLogger("Another");
        logger2.Trace("trace log message");
        logger2.Debug("debug log message");
        logger2.Info("info log message");
        logger2.Warn("warn log message");
        logger2.Error("very serious error log message");
        logger2.Fatal("fatal log message");
    }
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nlog-1.0.0.505.20100822 docs/examples/targets/Configuration API/ColoredConsole/Row Highlighting/Example.cs
nlog-1.0.0.505 docs/examples/targets/Configuration API/ColoredConsole/Row Highlighting/Example.cs
nlog-1.0.0.505-mswin32 docs/examples/targets/Configuration API/ColoredConsole/Row Highlighting/Example.cs