Cette page est affichée en anglais. Une traduction française est en cours.
ConfigsMay 24, 2026·2 min de lecture

Serilog — Structured Diagnostic Logging for .NET

A structured logging library for .NET applications that captures log events as rich data rather than plain text, with sinks for every major output target.

Prêt pour agents

Cet actif peut être lu et installé directement par les agents

TokRepo expose une commande CLI universelle, un contrat d'installation, le metadata JSON, un plan selon l'adaptateur et le contenu raw pour aider les agents à juger l'adaptation, le risque et les prochaines actions.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
Serilog Overview
Commande CLI universelle
npx tokrepo install 630c6c48-576b-11f1-9bc6-00163e2b0d79

Introduction

Serilog brings structured logging to the .NET ecosystem. Instead of formatting log messages into flat strings, it preserves named properties as queryable data, making logs far more useful for diagnostics and observability pipelines.

What Serilog Does

  • Captures log events as structured data with named properties
  • Routes output through a rich ecosystem of over 100 community sinks
  • Supports message templates with positional and named placeholders
  • Provides log enrichment to attach contextual data like machine name or thread ID
  • Integrates with ASP.NET Core, Microsoft.Extensions.Logging, and generic hosts

Architecture Overview

Serilog uses a pipeline model: log events flow through enrichers that add contextual properties, then through filters, and finally to one or more sinks. Each sink serializes events to a specific destination — console, files, Seq, Elasticsearch, Application Insights, or databases. Configuration can be done in C# fluent API or through appsettings.json via the Serilog.Settings.Configuration package.

Self-Hosting & Configuration

  • Install the core package with dotnet add package Serilog
  • Add sinks like Serilog.Sinks.File, Serilog.Sinks.Seq, or Serilog.Sinks.Elasticsearch
  • Configure minimum log level, enrichers, and sinks in appsettings.json
  • Use Serilog.AspNetCore for automatic HTTP request logging in ASP.NET Core
  • Enable destructuring policies to control how complex objects are serialized

Key Features

  • Message templates preserve structure without sacrificing readability
  • Over 100 sinks for console, files, databases, and observability platforms
  • Enrichers attach ambient context like correlation IDs and environment info
  • Sub-loggers allow per-component filtering and routing
  • Configuration via code or JSON with hot-reload support

Comparison with Similar Tools

  • NLog — XML-configured .NET logger; Serilog's structured data model is natively richer
  • log4net — classic Java-ported logger; Serilog is more modern with better async support
  • Microsoft.Extensions.Logging — abstractions layer; Serilog plugs in as a provider with more sink options
  • Seq — log server that pairs naturally with Serilog but works with any structured source

FAQ

Q: Can Serilog replace the built-in .NET logger? A: Yes. Use the Serilog.Extensions.Hosting package to replace the default ILogger provider.

Q: Does Serilog support async logging? A: Yes. The Serilog.Sinks.Async wrapper batches and writes events on a background thread.

Q: How does Serilog handle high-throughput scenarios? A: Batching sinks and the async wrapper minimize contention. Periodic batching sinks amortize I/O cost.

Q: Is Serilog compatible with .NET Framework? A: Yes. Serilog supports .NET Framework 4.6.2+ and .NET 6/7/8/9.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires