LowCodeHub.Logging 0.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package LowCodeHub.Logging --version 0.0.3
                    
NuGet\Install-Package LowCodeHub.Logging -Version 0.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LowCodeHub.Logging" Version="0.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LowCodeHub.Logging" Version="0.0.3" />
                    
Directory.Packages.props
<PackageReference Include="LowCodeHub.Logging" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LowCodeHub.Logging --version 0.0.3
                    
#r "nuget: LowCodeHub.Logging, 0.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package LowCodeHub.Logging@0.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LowCodeHub.Logging&version=0.0.3
                    
Install as a Cake Addin
#tool nuget:?package=LowCodeHub.Logging&version=0.0.3
                    
Install as a Cake Tool

LowCodeHub.Logging

A production-oriented logging library for ASP.NET Core built on Serilog. One extension method configures structured logging, HTTP request enrichment, sensitive data masking, file/console sinks, Application Insights, forwarded headers, and self-diagnostics — with safe defaults and PII-conscious enrichment.

NuGet License: MIT

Why This Library?

Feature LowCodeHub.Logging Raw Serilog Setup Default ASP.NET Logging
Setup One extension method 50+ lines of config Built-in but limited
HTTP enrichment PII-conscious defaults Manual middleware Request logging only
Exception destructuring Built-in — Refit, EF Core, SqlClient Manual Stack trace only
Sensitive data masking Allowlisted query keys Manual None
File sink Pre-configured rolling + retention Manual setup None
Application Insights One toggle Manual sink + DI Separate SDK
Forwarded headers Integrated proxy config Separate middleware Separate middleware
Self-diagnostics Built-in Serilog SelfLog Manual None
Startup validation Fail-fast on invalid config Silent failures Silent failures

Installation

dotnet add package LowCodeHub.Logging

Quick Start

using LowCodeHub.Logging.Extensions;

var builder = WebApplication.CreateBuilder(args);

builder.AddEnhancedSerilogLogging(
    loggingSection: "LoggingOptions",
    telemetrySection: "TelemetryOptions");

var app = builder.Build();

app.UseHttpContextEnricher();

app.MapGet("/", () => "ok");
app.Run();

That's it. Your application now has structured console + file logging, HTTP request enrichment (with PII-safe defaults), exception destructuring for Refit/EF Core/SqlClient, and optional Application Insights — all from two lines of setup.


Table of Contents


Configuration

Full Configuration Example

{
  "LoggingOptions": {
    "ServiceName": "orders-api",
    "MinimumLogLevel": "Information",
    "WriteToFile": true,
    "ConsoleLogging": {
      "UseCompactJson": true,
      "Theme": "literate"
    },
    "FileLogging": {
      "LogDirectory": "Logs",
      "LogFileName": "app.log",
      "RollingInterval": "Day",
      "RetainedFileCountLimit": 14,
      "SharedFile": true
    },
    "ExceptionHandling": {
      "MaxDestructuringDepth": 3
    },
    "RequestEnrichment": {
      "IncludeQueryString": false,
      "IncludeAuthenticatedUser": false,
      "IncludeUserRoles": false,
      "IncludeUserAgent": true,
      "IncludeReferer": false,
      "AllowedQueryKeys": ["page", "pageSize"]
    },
    "ForwardedHeaders": {
      "Enabled": true,
      "ForwardLimit": 1,
      "RequireHeaderSymmetry": true,
      "KnownProxies": ["10.0.0.10"],
      "KnownNetworks": ["10.244.0.0/16"]
    },
    "SelfLog": {
      "Enabled": true,
      "WriteToConsoleError": true,
      "FilePath": "Logs/serilog-selflog.txt"
    }
  },
  "TelemetryOptions": {
    "Enabled": false,
    "ConnectionString": ""
  }
}

Logging Options

Option Default Description
ServiceName required Service name added to every log entry
MinimumLogLevel Information Minimum log level (Verbose, Debug, Information, Warning, Error, Fatal)
WriteToFile false Enable file sink

Console Logging

Option Default Description
UseCompactJson true Use compact JSON format (recommended for containers)
OutputTemplate Serilog default Custom output template (when not using compact JSON)
Theme "literate" Console theme

File Logging

Option Default Description
LogDirectory "Logs" Directory for log files
LogFileName "log.txt" Log file name
RollingInterval Day Rolling interval (Infinite, Year, Month, Day, Hour, Minute)
RetainedFileCountLimit 15 Number of log files to retain
SharedFile true Allow shared file access (for multi-process scenarios)
OutputTemplate Serilog default Custom output template

Request Enrichment

Option Default Description
IncludeQueryString false Log query string values
IncludeAuthenticatedUser false Log authenticated user identity
IncludeUserRoles false Log user role claims
IncludeUserAgent true Log User-Agent header
IncludeReferer false Log Referer header
AllowedQueryKeys [] Allowlist for query string keys (only logged when IncludeQueryString is true)

Forwarded Headers

Option Default Description
Enabled true Enable X-Forwarded-For / X-Forwarded-Proto handling
ForwardLimit 1 Max hops to process
RequireHeaderSymmetry true Require header count symmetry
KnownProxies [] Trusted proxy IP addresses
KnownNetworks [] Trusted proxy networks (CIDR notation)

Self-Diagnostics

Option Default Description
Enabled false Enable Serilog SelfLog for diagnosing sink/serialization failures
WriteToConsoleError true Write SelfLog to stderr
FilePath null Optional file path for SelfLog output

Application Insights

Option Default Description
Enabled required Enable Application Insights telemetry
ConnectionString null Application Insights connection string

When Enabled=true, the library registers AI telemetry and writes Serilog traces to the DI-managed TelemetryConfiguration.


Exception Destructuring

Built-in destructurers extract structured data from common exception types:

Destructurer Exception Type What It Extracts
ApiExceptionDestructurer Refit ApiException Status code, URI, content, reason phrase
ApiExceptionDestructurer Refit ValidationApiException Validation errors
DbUpdateExceptionDestructurer EF Core DbUpdateException Entity type, state, properties
SqlExceptionDestructurer SqlException Error number, state, procedure, line

These are registered automatically — no additional configuration needed.


HTTP Context Enrichment

app.UseHttpContextEnricher(); // register early in the middleware pipeline

The enricher adds contextual properties to every log entry during HTTP request processing. What gets logged depends on your RequestEnrichment configuration:

  • Always: Request path, HTTP method, response status code, client IP
  • Opt-in: Query string (allowlisted keys only), authenticated user, user roles, User-Agent, Referer

Health endpoint logs (/health path) are excluded by default.


How It Works

┌─────────────────────────────────────────────────────────┐
│  AddEnhancedSerilogLogging(loggingSection, telemetry)   │
└─────────────────────┬───────────────────────────────────┘
                      │
    ┌─────────────────┼─────────────────┐
    ▼                 ▼                 ▼
┌──────────┐   ┌──────────────┐   ┌──────────────────┐
│ Serilog  │   │ Enrichers    │   │ Destructurers    │
│ Sinks    │   │              │   │                  │
├──────────┤   ├──────────────┤   ├──────────────────┤
│Console   │   │Service Name  │   │ApiException      │
│(compact  │   │Correlation   │   │DbUpdateException │
│ JSON)    │   │HTTP Context  │   │SqlException      │
│          │   │Machine Name  │   │                  │
│File      │   │Environment   │   │                  │
│(rolling) │   │Thread        │   │                  │
│          │   │              │   │                  │
│App       │   │              │   │                  │
│Insights  │   │              │   │                  │
└──────────┘   └──────────────┘   └──────────────────┘
  1. Configuration validation — Options are validated at startup. Invalid configuration fails fast.
  2. Serilog bootstrap — Console + Debug sinks are configured first for startup logging.
  3. Host integrationUseSerilog() replaces the default logger with the configured Serilog pipeline.
  4. Request logging — Serilog's UseSerilogRequestLogging() adds HTTP request logging middleware.
  5. HTTP enrichmentUseHttpContextEnricher() adds contextual properties per request.

Best Practices

  1. Set a real ServiceName per service.
  2. Keep IncludeQueryString=false unless you truly need it.
  3. If query logging is enabled, use AllowedQueryKeys allowlist only.
  4. Keep user identity fields disabled by default in public-facing APIs.
  5. Configure KnownProxies / KnownNetworks in Kubernetes or behind ingress.
  6. Enable SelfLog in production to catch sink/serialization failures.
  7. Use compact JSON logs in containerized environments.
  8. Keep file retention bounded to avoid disk exhaustion.
  9. Enable Application Insights only when you provide a valid connection string.

Requirements

  • .NET 10 or later
  • Serilog.AspNetCore 10.0+ (included as a dependency)
  • Microsoft.ApplicationInsights.AspNetCore (included — optional, enable via config)

License

MIT © Ahmed Abuelnour

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.11 206 7/9/2026
0.0.10 152 6/21/2026
0.0.4 169 5/18/2026
0.0.3 121 5/12/2026
0.0.2 149 4/23/2026
0.0.1 154 3/26/2026