Skip to main content

Logging — Troubleshooting Guide

A practical guide for solving the most common issues when integrating PrimusSaaS.Logging.


Installation Issues

Package Not Found on NuGet

Error: Unable to find package 'PrimusSaaS.Logging'

Cause: The package is on a private NuGet feed.

Fix:

# Add the private feed (get URL from your team admin)
dotnet nuget add source https://your-feed-url/v3/index.json --name PrimusNuGet

# Verify the feed was added
dotnet nuget list source

# Then install
dotnet add package PrimusSaaS.Logging --version 1.2.6

Version Not Found

Error: Package 'PrimusSaaS.Logging 1.2.6' is not found

Fix: Check what versions are available:

dotnet package search PrimusSaaS.Logging --source PrimusNuGet

Setup Issues

No Logs Appearing

Cause A: MinLevel is set too high.

// appsettings.json — change MinLevel to 0 for all logs
"PrimusLogging": {
"MinLevel": 0
}

Cause B: builder.Logging.ClearProviders() was not called — default providers may be filtering logs before Primus sees them.

builder.Logging.ClearProviders(); // Always call this first
builder.Logging.AddPrimus(builder.Configuration.GetSection("PrimusLogging"));

Cause C: No targets configured in appsettings.json. Make sure you have at least one target:

"Targets": [
{ "Type": "console", "Pretty": true }
]

InvalidOperationException on Startup

Error: InvalidOperationException: Cannot resolve scoped service...

Fix: Ensure your Program.cs order is correct:

var builder = WebApplication.CreateBuilder(args);

builder.Logging.ClearProviders();
builder.Logging.AddPrimus(builder.Configuration.GetSection("PrimusLogging")); // BEFORE Build()

var app = builder.Build();

app.UsePrimusLogging(); // AFTER Build()
app.MapControllers();
app.Run();

Duplicate Log Entries

Cause: Default logging providers weren't cleared before adding Primus.

Fix:

builder.Logging.ClearProviders(); // Add this line
builder.Logging.AddPrimus(...);

Runtime Issues

PII Masking Not Working

Check 1: Make sure EnablePiiMasking is not set to false:

"PrimusLogging": {
"EnablePiiMasking": true // default is true, don't set to false
}

Check 2: PII masking applies to structured log parameters. If you're concatenating strings directly, it won't mask:

// ✅ CORRECT — structured parameter, will be masked
_logger.LogInformation("User email: {Email}", userEmail);

// ❌ WRONG — string interpolation, will NOT be masked
_logger.LogInformation($"User email: {userEmail}");

Correlation ID Not Appearing in Logs

Cause: app.UsePrimusLogging() was not added in Program.cs.

Fix: Add it after builder.Build():

var app = builder.Build();
app.UsePrimusLogging(); // This generates and attaches Correlation IDs

Note: You can also pass a Correlation ID from the client via the X-Correlation-Id request header, and Primus will use it automatically.

No Colored Output in Terminal

Cause: Running inside Docker, CI, or a terminal that doesn't support ANSI codes.

Fix: Set Pretty to false for non-interactive environments:

"Targets": [
{
"Type": "console",
"Pretty": false // Plain text output, no ANSI colors
}
]

Which AddPrimus Overload Should I Use?

All three overloads are valid — pick based on your setup:

// Option A — appsettings.json binding (recommended for most apps)
builder.Logging.AddPrimus(builder.Configuration.GetSection("PrimusLogging"));

// Option B — code-based configuration
builder.Logging.AddPrimus(opts =>
{
opts.ApplicationId = "MyApp";
opts.Environment = "Production";
opts.Targets = new List<TargetConfig> { new TargetConfig { Type = "console" } };
});

// Option C — bind from config AND override in code
builder.Logging.AddPrimus(builder.Configuration.GetSection("PrimusLogging"), opts =>
{
opts.ApplicationId = "Override"; // override specific values
});

// Option D — zero config defaults (useful for unit tests)
builder.Logging.AddPrimus();

Still Stuck?

  1. Check the Advanced Guide for complex scenarios
  2. Check the GitHub Issues
  3. Run the Minimal Example to verify your environment works first