Logging Module Overview
Enterprise-grade structured logging with automatic PII masking, correlation IDs, and multiple output targets. Drop-in replacement for ILogger<T>.
Why Use Primus Logging?
Standard logging lacks PII protection and cross-service correlation. Primus Logging provides automatic masking, context enrichment, and flexible targets all with zero changes to your existing ILogger<T> code.
| Feature | Standard Logging | Primus Logging |
|---|---|---|
| PII Masking | Manual | Automatic |
| Correlation IDs | DIY | Built-in |
| Multiple Targets | Complex | Config-only |
| Structured Output | Varies | Consistent |
Supported Destinations
Console
Colored, formatted output for development and debugging.
Application Insights
Azure Monitor integration for cloud-native observability.
File Output
Async buffered file output with rotation and compression.
Serilog Bridge
Forward enriched logs to existing Serilog pipelines.
NLog Bridge
Forward enriched logs to existing NLog configurations.
Result Object (LogEntry)
Each log entry contains enriched context:
| Property | Type | Description |
|---|---|---|
Timestamp | DateTime | When the log was created |
Level | LogLevel | Debug, Info, Warning, Error, Critical |
Message | string | Formatted message (PII masked) |
Category | string | Logger category (class name) |
CorrelationId | string | Request correlation ID |
ApplicationId | string | Configured application name |
Environment | string | Deployment environment |
Properties | Dictionary | Structured data fields |
Exception | ExceptionInfo? | Exception details if present |
PII Masking Result
When PII masking is enabled, sensitive data is automatically replaced:
| Original | Masked |
|---|---|
user@example.com | u***@***.com |
4111111111111111 | ************1111 |
123-45-6789 | ***-**-**** |
Log Levels
| Level | Value | Use Case |
|---|---|---|
| Debug | 0 | Detailed diagnostics |
| Info | 1 | Operational messages |
| Warning | 2 | Unexpected but recoverable |
| Error | 3 | Non-fatal errors |
| Critical | 4 | Fatal errors |
Target Options
| Target | Configuration | Description |
|---|---|---|
| Console | { "Type": "console", "Pretty": true } | Colored dev output |
| File | { "Type": "file", "Path": "logs/app.log" } | File with rotation |
| Application Insights | { "Type": "applicationInsights" } | Azure telemetry |
| Serilog | { "Type": "serilog" } | Bridge to Serilog |
| NLog | { "Type": "nlog" } | Bridge to NLog |
Next Steps
| Want to... | See Guide |
|---|---|
| Log to console (dev) | Console |
| Send to Azure Monitor | Application Insights |
| Write to files | File Output |
| Use with Serilog | Serilog Bridge |
| Use with NLog | NLog Bridge |
| Advanced features | Advanced |
Before You Begin — NuGet Feed Setup
PrimusSaaS.Logging is distributed via NuGet. If your organization uses a private feed, you need to register it first:
dotnet nuget add source https://your-feed-url/v3/index.json --name PrimusNuGet
Then install:
dotnet add package PrimusSaaS.Logging --version 1.2.6
Supports: .NET 6, 7, 8, 9
If you're unsure of the feed URL, contact your Primus SaaS admin or check the Integration Guide.
Common Mistakes to Avoid
| Mistake | Fix |
|---|---|
Calling app.UsePrimusLogging() before builder.Build() | Always call it after var app = builder.Build() |
Skipping builder.Logging.ClearProviders() | This causes duplicate log output from default providers |
Setting MinLevel too high in production | Start with 1 (Info) and adjust per environment |
Leaving "Pretty": true in Docker/CI | Set "Pretty": false — ANSI colors break plain log aggregators |