serilog

Configure Serilog for structured .NET logging with appsettings-driven sinks and OTLP export.

1|Updated Mar 27, 2026
One-click install
npx skills add https://github.com/Maj3D10/Training-Platform --skill serilog-maj3d10
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: serilog
Source: https://github.com/Maj3D10/Training-Platform/tree/main/.agent/skills/serilog
Command: npx skills add https://github.com/Maj3D10/Training-Platform --skill serilog-maj3d10

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Serilog helps you produce structured, queryable application logs that stay consistent across startup, DI, configuration, and production environments.

Core Features & Use Cases

  • Two-stage logging for reliable startup diagnostics: Use a bootstrap logger to capture startup failures, then switch to the full DI/configured logger.
  • Configuration-driven sinks, levels, enrichers, and overrides: Centralize behavior in appsettings.json for per-environment changes without redeploying.
  • Structured logging, destructuring, and contextual enrichment: Emit message templates, preserve object structure with targeted destructuring, and attach request/scope properties via LogContext and request logging middleware.
  • Filtering and telemetry integration: Use Serilog.Expressions for expression-based filtering and optionally export directly via the OTLP sink.

Quick Start

Ask the AI to generate an appsettings.json plus minimal .NET 10 startup code that configures Serilog with appsettings-driven sinks, structured request logging, LogContext enrichment, and safe destructuring limits.

Frequently Asked Questions about serilog

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I configure structured logging in .NET with Serilog?

Use a two-stage bootstrap initialization to capture startup diagnostics early, then switch to a full DI-integrated logger configured via appsettings.json. This ensures startup failures are logged before the application pipeline is fully operational.

Can I use appsettings.json to manage Serilog log levels and sinks?

Yes, appsettings.json drives Serilog sink configuration, log levels, enrichers, and per-environment overrides. This centralizes behavior without redeployment, applying configured changes directly to the .NET logging pipeline.

How does Serilog request logging enrich HTTP requests in .NET?

Serilog request logging enriches HTTP requests by attaching contextual properties via LogContext and request logging middleware. It uses safe destructuring limits to preserve object structure, emitting structured events queryable across production environments.

What's the best way to export .NET logs via OTLP using Serilog?

Export .NET logs via OTLP using the optional Serilog OTLP sink combined with Serilog.Expressions for expression-based filtering. This forwards structured events directly to telemetry platforms without requiring separate agent-side parsing.

Why are my Serilog logs missing during application startup?

Missing Serilog logs during startup occur when the DI-integrated logger is uninitialized. A two-stage bootstrap logger captures early startup failures before switching to the full appsettings-driven configuration, ensuring no diagnostics are lost.

How do I safely flush .NET structured logs on application shutdown?

Safely flush .NET structured logs on shutdown by calling CloseAndFlushAsync on the Serilog logger. This ensures all buffered events are written to configured sinks before the application process terminates completely.