A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/NLog/NLog/wiki/ColoredConsole-target below:

ColoredConsole target · NLog/NLog Wiki · GitHub

Writes log messages to the console with customizable coloring.

Platforms Supported: All

There is also the simple Console-Target without any overhead from coloring.

<targets>
  <target xsi:type="ColoredConsole"
          name="String"
          encoding="Encoding"
          layout="Layout"
          header="Layout"
          footer="Layout"
          useDefaultRowHighlightingRules="Boolean"
          stderr="Boolean"
          enableAnsiOutput="Boolean"
          detectConsoleAvailable="Boolean"
          detectOutputRedirected="Boolean">
    <highlight-row condition="Condition" backgroundColor="Enum" foregroundColor="Enum"/><!-- repeated -->
    <highlight-word text="String" condition="Condition" backgroundColor="Enum" foregroundColor="Enum"
                    ignoreCase="Boolean" wholeWords="Boolean" /><!-- repeated -->
  </target>
</targets>

Read more about using the Configuration File.

NLog v6 changed the default rules not use yellow for Error and maganta for Warn Colors :

Condition Foreground Color Background Color level == LogLevel.Fatal Red NoChange level == LogLevel.Error Red NoChange level == LogLevel.Warn Yellow NoChange level == LogLevel.Info White NoChange level == LogLevel.Debug Gray NoChange level == LogLevel.Trace Gray NoChange

NLog v6 no longer supports word-highlight using Regular Expressions (RegEx) and removed these options:

Color Enum Description HEX Code ANSI Foreground ANSI Background NoChange Don't change the color Black Black Color #000000 \x1B[30m \x1B[40m Blue Blue Color #0000FF \x1B[94m \x1B[104m Cyan Cyan Color #00FFFF \x1B[96m \x1B[106m DarkBlue Dark Blue Color #000080 \x1B[34m \x1B[44m DarkCyan Dark Cyan Color #008080 \x1B[36m \x1B[46m DarkGray Dark Gray Color #808080 \x1B[90m \x1B[100m DarkGreen Dark Green Color #008000 \x1B[32m \x1B[42m DarkMagenta Dark Magenta Color #800080 \x1B[35m \x1B[45m DarkRed Dark Red Color #800000 \x1B[31m \x1B[41m DarkYellow Dark Yellow Color #808000 \x1B[33m \x1B[43m Gray Gray Color #C0C0C0 \x1B[37m \x1B[47m Green Green Color #00FF00 \x1B[92m \x1B[102m Magenta Magenta Color #FF00FF \x1B[95m \x1B[105m Red Red Color #FF0000 \x1B[91m \x1B[101m White White Color #FFFFFF \x1b[97m \x1B[107m Yellow Yellow Color #FFFF00 \x1B[93m \x1B[103m
var consoleTarget = new ColoredConsoleTarget();

var highlightRule = new ConsoleRowHighlightingRule();
highlightRule.Condition = ConditionParser.ParseExpression("level == LogLevel.Info");
highlightRule.ForegroundColor = ConsoleOutputColor.Green;
consoleTarget.RowHighlightingRules.Add(highlightRule);
Microsoft Extension Logging AddConsole

The NLog Layout of the ColoredConsole-Target can be configured to match the output of the default MEL AddConsole().

See also NLog Console and AddConsole

Visual Studio Output window

The Visual Studio "Output Window" is bit tricky with colors. It is not a real console window - it just displays the console output from the application.

You could get colors by prefixing the message in your config (Ex. Layout="${level:format=FulleName}: ${message}")

See Stackoverflow

Or use The Visual Studio extension VSColorOutput (VS2015-2019). Then you could also use the regular Console target.

Missing colors for dotnet watch run

When running application using dotnet watch run then one might experience that console colors are missing.

This can be fixed by changing launchSettings.json and removing the entry launchBrowser and the colors should return.

See also: https://github.com/dotnet/aspnetcore/issues/25317


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4