Pragmatic.Logging
Feature-rich structured logging for the Pragmatic.Design ecosystem: extends .NET ILogger with
privacy-aware redaction, an audit trail, context enrichment, an expression filter DSL, and multiple
providers.
Performance: with every library writing into a sink that renders and reads the event, Pragmatic is ahead of Serilog and NLog in every benchmarked scenario, the production preset with context enrichment included, and behind ZLogger everywhere. See BENCHMARK-RESULTS.md for the run, the machine and the reports.
The Problem
Section titled “The Problem”Production logging needs structured output, PII redaction, correlation IDs, rate limiting, and multiple
targets. Microsoft.Extensions.Logging gives you the ILogger foundation and
leaves the rest to you. String interpolation allocates on every call (even when the level is off),
secrets leak when someone forgets to sanitize, and context must be threaded by hand.
// Without Pragmatic: allocates always, leaks PII + secrets, no contextlogger.LogInformation($"Order {orderId} by {email} via {connectionString}");The Solution
Section titled “The Solution”A fluent PragmaticLoggingBuilder over standard ILogger<T> (no proprietary abstraction) configures
every concern in one place: providers, presets, privacy, performance, context enrichment.
builder.Services.AddPragmaticLogging(logging => logging .UseProductionPreset() // background processing, rate limiting, correlation IDs .AddConsole() .AddFile("logs/app-{Date}.log") // rolling file with retention .EnableDataRedaction(r => r.SensitivePropertyNames = ["password", "email", "apiKey"]));In a Pragmatic host the same builder is app.UseLogging(logging => …). There is one builder,
Pragmatic.Logging.Extensions.PragmaticLoggingBuilder; ILoggingBuilder.AddPragmaticLogging() no
longer exists.
On hot paths, write [LoggerMessage] methods: with Pragmatic.SourceGenerator referenced they are
Pragmatic call sites, whose state writes itself as UTF-8 and masks a
[PersonalData] argument at the call site. Structured properties, automatic PII/secret redaction, an
audit trail, and context enrichment come built in.
Installation
Section titled “Installation”dotnet add package Pragmatic.LoggingStatus
Section titled “Status”Functional within 1.0.0-alpha: the builder, the providers (console, rolling file, JSON, NDJSON, memory, debug, null, Windows Event Log), presets, redaction, the audit trail, rate limiting, and context enrichment. See the roadmap.
| Concepts | The builder model, presets, zero-allocation infrastructure |
| Getting Started | Configure providers and write your first structured logs |
| Providers | The eight providers, choosing one, writing your own |
| Context Enrichment | Correlation IDs, ambient context, scopes |
| Privacy & Security | PII/secret redaction, audit trail |
| Log call sites | [LoggerMessage] with the Pragmatic generator: UTF-8 state, masking at the call site |
| Performance | [LoggerMessage], the zero-allocation formatter, rate limiting |
| Common Mistakes | The most frequent logging pitfalls |
| Troubleshooting | Problem/solution guide |
Requirements
Section titled “Requirements”- .NET 10.0+
License
Section titled “License”Part of the Pragmatic.Design ecosystem. See Licensing. Pragmatic.Logging is MIT-licensed.
