- Cross-platform implementation supporting asynchronous Console logging.
- Configurable default minimum log level.
- Single-line, Multi-line or Custom log entry formats.
- Indent multiline messages for easier reading and analysis.
- Configurable color scheme for Console log messages, for easier reading.
- Per-provider log level filtering via
Logging:ConsoleLogger:LogLevelinappsettings.json.
.NET 8, .NET 9, .NET 10.
using ConsoleLoggerLibrary;
...<omitted>...
.ConfigureLogging((context, builder) =>
{
builder.ClearProviders();
builder.AddConsoleLogger();
})When the host registers IConfiguration (e.g. via Host.CreateDefaultBuilder),
the no-arg AddConsoleLogger() automatically binds options from the
Logging:ConsoleLogger section — no need to pass IConfiguration explicitly.
appsettings.json -- all options shown
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Error"
},
"ConsoleLogger": {
"LogMinLevel": "Debug",
"UseUtcTimestamp": false,
"MultiLineFormat": false,
"IndentMultilineMessages": true,
"EnableConsoleColors": true,
"LogLevelColors": {
"Trace": "Cyan",
"Debug": "Blue",
"Information": "Green",
"Warning": "Yellow",
"Error": "Red",
"Critical": "Magenta",
"None": "White"
}
}
}
}Program.cs -- full file for complete context
using ConsoleLoggerLibrary;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace ConsoleLoggerDemo;
internal class Program
{
static async Task Main(string[] args)
{
try
{
await Host.CreateDefaultBuilder(args)
.ConfigureLogging((context, builder) =>
{
builder.ClearProviders();
builder.AddConsoleLogger();
})
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<App>();
})
.RunConsoleAsync();
}
catch (Exception ex)
{
Console.WriteLine($"Unexpected error: {ex.Message}");
}
}
}If your host doesn't register
IConfigurationautomatically, pass it explicitly:builder.AddConsoleLogger(context.Configuration);
Program.cs -- full file for complete context, all ConsoleLoggerOptions shown
using ConsoleLoggerLibrary;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace ConsoleLoggerDemo;
internal class Program
{
static async Task Main(string[] args)
{
try
{
await Host.CreateDefaultBuilder(args)
.ConfigureLogging((context, builder) =>
{
builder.ClearProviders();
builder.AddConsoleLogger(configure =>
{
configure.LogMinLevel = LogLevel.Trace;
configure.UseUtcTimestamp = false;
configure.MultiLineFormat = false;
configure.IndentMultilineMessages = true;
configure.EnableConsoleColors = true;
configure.LogLevelColors = new()
{
[LogLevel.Trace] = ConsoleColor.Cyan,
[LogLevel.Debug] = ConsoleColor.Blue,
[LogLevel.Information] = ConsoleColor.Green,
[LogLevel.Warning] = ConsoleColor.Yellow,
[LogLevel.Error] = ConsoleColor.Red,
[LogLevel.Critical] = ConsoleColor.DarkRed,
[LogLevel.None] = ConsoleColor.White
};
});
})
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<App>();
})
.RunConsoleAsync();
}
catch (Exception ex)
{
Console.WriteLine($"Unexpected error: {ex.Message}");
}
}
}Because the provider registers itself via
LoggerProviderOptions.RegisterProviderOptions, you can scope per-category
log levels to just this provider (independent of the global Logging:LogLevel
section) by adding a LogLevel subsection under ConsoleLogger:
"Logging": {
"LogLevel": {
"Default": "Information"
},
"ConsoleLogger": {
"LogMinLevel": "Trace",
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Warning",
"MyApp.Diagnostics": "Trace"
}
}
}LogMinLevel sets the floor honored by this provider. The framework's
global MinLevel is automatically lowered to match when LogMinLevel
is more permissive (e.g. Trace), so per-provider Trace/Debug entries
aren't filtered out before reaching the writer.
IndentMultilineMessages=true
2026-04-19--18.10.20|INFO|ConsoleLoggerDemo.App|{
"Date": "4/19/2026",
"Location": "Center Moriches",
"TemperatureCelsius": 20,
"Summary": "Nice"
}
IndentMultilineMessages=false
2026-04-19--18.11.19|INFO|ConsoleLoggerDemo.App|{
"Date": "4/19/2026",
"Location": "Center Moriches",
"TemperatureCelsius": 20,
"Summary": "Nice"
}
Note: The IndentMultilineMessages option is only for the Single-Line message format.
The package ships portable PDBs with
Source Link embedded and a
companion .snupkg symbol package. Enable "Source Link support" in
Visual Studio (or JetBrains Rider) to step into the library directly
from your debugger.
See GitHub Releases for the changelog.
https://docs.microsoft.com/en-us/dotnet/core/extensions/custom-logging-provider


