Skip to main content

Logging Module Overview

Try in Playground

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.

FeatureStandard LoggingPrimus Logging
PII MaskingManualAutomatic
Correlation IDsDIYBuilt-in
Multiple TargetsComplexConfig-only
Structured OutputVariesConsistent

Supported Destinations


Result Object (LogEntry)

Each log entry contains enriched context:

PropertyTypeDescription
TimestampDateTimeWhen the log was created
LevelLogLevelDebug, Info, Warning, Error, Critical
MessagestringFormatted message (PII masked)
CategorystringLogger category (class name)
CorrelationIdstringRequest correlation ID
ApplicationIdstringConfigured application name
EnvironmentstringDeployment environment
PropertiesDictionaryStructured data fields
ExceptionExceptionInfo?Exception details if present

PII Masking Result

When PII masking is enabled, sensitive data is automatically replaced:

OriginalMasked
user@example.comu***@***.com
4111111111111111************1111
123-45-6789***-**-****

Log Levels

LevelValueUse Case
Debug0Detailed diagnostics
Info1Operational messages
Warning2Unexpected but recoverable
Error3Non-fatal errors
Critical4Fatal errors

Target Options

TargetConfigurationDescription
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 MonitorApplication Insights
Write to filesFile Output
Use with SerilogSerilog Bridge
Use with NLogNLog Bridge
Advanced featuresAdvanced

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

MistakeFix
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 productionStart with 1 (Info) and adjust per environment
Leaving "Pretty": true in Docker/CISet "Pretty": false — ANSI colors break plain log aggregators