Skip to main content

Logging Module - Overview

Enterprise-grade structured logging with automatic context enrichment, PII masking, async buffering, and multiple output targets. Drop-in replacement for ILogger<T> with correlation IDs, performance tracking, and HTTP context enrichment.

Packages

  • .NET: PrimusSaaS.Logging (current: 1.2.6)
  • Node.js: Coming soon

Key Capabilities

  • Drop-in replacement for ILogger<T> interface
  • PII masking (emails, credit cards, SSNs, custom fields)
  • Multiple targets (Console, File, Azure Application Insights, Serilog, NLog)
  • Automatic request/correlation ID enrichment
  • Async buffering with non-blocking writes
  • Performance timer utilities

Example API

GET /ping
Response 200:

{
"message": "pong"
}

Console output shows structured log with request ID, method, path, and timing.

Quick Install

# .NET
dotnet add package PrimusSaaS.Logging --version 1.2.6

.NET Example

using PrimusSaaS.Logging.Extensions;

var builder = WebApplication.CreateBuilder(args);

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

var app = builder.Build();
app.UsePrimusLogging();
app.MapControllers();
app.Run();

appsettings.json:

{
"PrimusLogging": {
"ApplicationId": "my-api",
"MinLevel": 1,
"Targets": [
{ "Type": "console", "Pretty": true },
{ "Type": "file", "Path": "logs/app.log", "Async": true }
],
"Pii": {
"MaskEmails": true,
"MaskCreditCards": true
}
}
}

Controller Example

[ApiController]
[Route("api/[controller]")]
public class UsersController : ControllerBase
{
private readonly ILogger<UsersController> _logger;

public UsersController(ILogger<UsersController> logger) => _logger = logger;

[HttpGet("{id}")]
public IActionResult Get(int id)
{
_logger.LogInformation("Fetching user {UserId}", id);
return Ok(new { UserId = id, Name = "John Doe" });
}
}

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

Log Levels

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

See Also