Simple.Logging.Console
2.0.0
dotnet add package Simple.Logging.Console --version 2.0.0
NuGet\Install-Package Simple.Logging.Console -Version 2.0.0
<PackageReference Include="Simple.Logging.Console" Version="2.0.0" />
<PackageVersion Include="Simple.Logging.Console" Version="2.0.0" />
<PackageReference Include="Simple.Logging.Console" />
paket add Simple.Logging.Console --version 2.0.0
#r "nuget: Simple.Logging.Console, 2.0.0"
#:package Simple.Logging.Console@2.0.0
#addin nuget:?package=Simple.Logging.Console&version=2.0.0
#tool nuget:?package=Simple.Logging.Console&version=2.0.0
Simple log formatter 🌈
A way to simplify console logging from the default C# fancy 2 line logging that provides way too much information for simple applications.
- Has some simple coloring related to log levels.
- Has some highlight formatting when placing text between
'single quotes'or`backticks`. - Colors are configurable per log level via a
LogPalette.
Usage
dotnet add package Simple.Logging.Console
In your startup code
var builder = Host.CreateApplicationBuilder(arguments);
builder.Logging.AddConsoleLogging();
AddConsoleLogging uses the ANSI 16-color formatter, which renders correctly on any terminal that understands SGR escape codes. For 24-bit truecolor, use AddRgbConsoleLogging instead (see Custom palette).
Highlighting
Text wrapped in 'single quotes' is drawn in the level's highlight color; text wrapped in `backticks` is drawn in its accent color. The two delimiters don't nest inside each other — a backtick inside a quoted span (or vice versa) is treated as literal text.
Custom palette
Pass a delegate to override any of the per-level colors, the timestamp color, the exception color, or the highlight/accent delimiter characters. Palettes are homogeneous: AddConsoleLogging configures a LogPalette<AnsiColor> (standard ConsoleColor values, implicitly convertible), and AddRgbConsoleLogging configures a LogPalette<RgbColor> (24-bit truecolor). Each color slot is an IConsoleColor; a single palette can't mix the two, which is what keeps the formatter allocation-free (no boxing, no per-line escape-string allocation).
ANSI (works everywhere):
builder.Logging.AddConsoleLogging(configurePalette: palette =>
{
palette.Warning = palette.Warning with { AccentColor = ConsoleColor.DarkYellow };
palette.HighlightDelimiter = '*';
palette.AccentDelimiter = '~';
});
Truecolor:
builder.Logging.AddRgbConsoleLogging(configurePalette: palette =>
{
palette.Warning = palette.Warning with { AccentColor = RgbColor.FromHex(0xFF8800) };
palette.Information = palette.Information with { MessageColor = new RgbColor(0, 200, 255) };
});
Truecolor renders correctly on modern ANSI-capable terminals; if output is redirected to a file or viewed through a legacy console, Microsoft.Extensions.Logging.Console's own fallback only recognizes the standard 16 colors, so truecolor escape sequences may appear as raw text there — use AddConsoleLogging if that scenario matters to you.
LogPalette.LikelySupportsTrueColor is a best-effort, static heuristic (COLORTERM, WT_SESSION, NO_COLOR, and whether output is redirected) you can check before choosing which formatter to register:
if (LogPalette.LikelySupportsTrueColor)
builder.Logging.AddRgbConsoleLogging();
else
builder.Logging.AddConsoleLogging();
There's no way to reliably query a terminal's actual color depth without risking a hang on redirected output, so treat this as a hint, not a guarantee.
Each level's badge background defaults to transparent so it doesn't clash with the terminal's own background; Error and Critical are the exception, keeping a filled block to stand out.
Disabling color
By default the formatters honor the NO_COLOR convention: if the NO_COLOR environment variable is set to anything non-empty, output is emitted as plain text (no escape codes) — the highlight/accent delimiters are still consumed, so lines stay readable. This is controlled by LogPalette<TColor>.RespectNoColor, which defaults to true. Set it false to always emit color, ignoring NO_COLOR:
builder.Logging.AddConsoleLogging(configurePalette: p => p.RespectNoColor = false);
Output redirection is intentionally not treated as a no-color signal (piping into a color-aware pager is common). RespectNoColor is read once when the formatter is constructed.
Previewing a palette
The samples/Simple.Logging.Console.Preview project renders every log level and color slot (badge, message, highlight, accent, timestamp, exception) for both the ANSI and RGB defaults — plus a NO_COLOR pass showing the plain-text fallback — so you can eyeball a palette before shipping it:
dotnet run --project samples/Simple.Logging.Console.Preview
Point it at your own palette by passing it to new RgbLogFormatter(palette) (or new ConsoleLogFormatter(palette)) in Program.cs.
Formerly published as
Crude.Logging.Console. That package is deprecated in favor of this one — see the changelog.
Icon
The package icon is a cropped version of "Rainbow Emoji" by EmmanuelCordoliani, used under CC BY-SA 4.0. It is licensed separately from the source code above (see LICENSE.txt); redistributing icon.png itself, modified or not, must keep it under CC BY-SA 4.0 (or a compatible license) with the same attribution.
Package maintainer
Change log
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.Logging.Console (>= 10.0.0 && < 11.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.