Skip to content

Pragmatic.Logging

High-performance structured logging for the Pragmatic.Design ecosystem — extends .NET ILogger with zero-allocation hot paths, privacy-aware redaction, audit trail, and multiple providers.

Production logging needs structured output, PII redaction, correlation IDs, rate limiting, and multiple targets — without adding latency. 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 context
logger.LogInformation($"Order {orderId} by {email} via {connectionString}");

A fluent PragmaticLoggingBuilder over standard ILogger<T> (no proprietary abstraction) configures every concern in one place — providers, presets, privacy, performance, context enrichment.

builder.Services.AddLogging(logging =>
{
logging.ClearProviders();
logging.AddPragmaticLogging()
.UseProductionPreset() // background processing, rate limiting, correlation IDs
.AddConsole()
.AddFile("logs/app-{Date}.log") // rolling file with retention
.EnableDataRedaction(r => r.SensitivePropertyNames = ["password", "email", "apiKey"]);
});

Use [LoggerMessage] source-generated logging for zero-allocation hot paths; structured properties, automatic PII/secret redaction, an audit trail, and context enrichment come built in.

Terminal window
dotnet add package Pragmatic.Logging

The builder, providers (console/file), presets, redaction, audit trail, rate limiting, and context enrichment are functional within the 0.8 preview. See the roadmap.

| Concepts | The builder model, presets, zero-allocation infrastructure | | Getting Started | Configure providers and write your first structured logs | | Providers | Console, rolling file, choosing a provider | | Context Enrichment | Correlation IDs, ambient context, scopes | | Privacy & Security | PII/secret redaction, audit trail | | Performance | [LoggerMessage], zero-allocation hot paths, rate limiting | | Common Mistakes | The most frequent logging pitfalls | | Troubleshooting | Problem/solution guide |

  • .NET 10.0+

Part of the Pragmatic.Design ecosystem — see Licensing. Pragmatic.Logging is MIT-licensed.