Serilog
Configures Serilog with a console formatter that colors log output by level and by property. Property values can also carry a color code in the message template, so the parts of a line that matter can be made to stand out without string concatenation.
Registration is a single call, and configuration is optional: without an IConfiguration the package adds log-context enrichment and its asynchronous console sink, leaving everything else to Serilog's defaults.
Categories
- Configuration — optional
Serilogsettings read fromappsettings.json. - Formatter — the console output format, color codes, and template syntax.
- Extensions — registration for service collections and host builders.
Quick Example
csharp
using AlmightyShogun.Serilog;
using Microsoft.Extensions.DependencyInjection;
builder.Services.AddCustomLogging(builder.Configuration);csharp
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
public sealed class ImportWorker(
ILogger<ImportWorker> logger
) : BackgroundService
{
protected override Task ExecuteAsync(CancellationToken stoppingToken)
{
logger.LogInformation(
"Imported {Count} rows in {Elapsed:N1|bg} ms",
4218,
92.47
);
return Task.CompletedTask;
}
}