Serilog.Extensions 10.0.0

dotnet add package Serilog.Extensions --version 10.0.0
                    
NuGet\Install-Package Serilog.Extensions -Version 10.0.0
                    
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="Serilog.Extensions" Version="10.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Serilog.Extensions" Version="10.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Serilog.Extensions" />
                    
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 Serilog.Extensions --version 10.0.0
                    
#r "nuget: Serilog.Extensions, 10.0.0"
                    
#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 Serilog.Extensions@10.0.0
                    
#: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=Serilog.Extensions&version=10.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Serilog.Extensions&version=10.0.0
                    
Install as a Cake Tool

Serilog Extensions for .NET

NuGet Version License: MIT

A lightweight library to simplify Serilog integration in .NET applications. It provides fluent extension methods for WebApplicationBuilder, IHostBuilder, and IServiceCollection, along with powerful conditional logging capabilities.

๐Ÿš€ Features

  • Zero-Config Setup: Get running with sensible defaults in one line.
  • Fluent Integration: Supports all modern .NET hosting patterns.
  • External JSON Config: Manage Serilog settings in separate files (e.g., appsettings.serilog.json).
  • Conditional Logging: Log messages based on boolean conditions (Assert, When, WhenNot).
  • Auto-Enrichment: Pre-configured with Process, Thread, and Environment enrichers.

๐Ÿ“ฆ Installation

dotnet add package Serilog.Extensions

๐Ÿ› ๏ธ Quick Start

WebApplicationBuilder (.NET 6/7/8/9/10+)

using Serilog.Extensions;

var builder = WebApplication.CreateBuilder(args);

// Setup Serilog using appsettings.json
builder.UseSerilog(); 

var app = builder.Build();
app.UseSerilogRequestLogging(); // Optional: Add request logging middleware
app.Run();

Generic Host (Worker Services / Console)

using Serilog.Extensions;

Host.CreateDefaultBuilder(args)
    .UseSerilog() // Uses host configuration
    .Build()
    .Run();

โš™๏ธ Advanced Configuration (External JSON)

If you prefer to keep your logging configuration separate from your main appsettings.json, use UseSerilogJson().

1. Update appsettings.json

Add the location of your logging config:

{
  "JsonFileSettingsOptions": [
    {
      "Filename": "serilog.config.json",
      "Optional": false,
      "ReloadOnChange": true
    }
  ]
}

2. Configure Builder

builder.UseSerilogJson();

3. Properties Table

Property Type Description
Filename string Path to the Serilog JSON configuration file.
Optional bool If false, throws an exception if the file is missing.
ReloadOnChange bool If true, updates logger settings without restarting the app.

๐Ÿ” Conditional Logging

Stop wrapping log calls in if statements. Use the built-in conditional extensions for cleaner code.

The Assert Pattern

Logs a message only if the condition is false (ideal for validation).

// Logs Error only if user is null
logger.AssertError(user != null, "User not found in database");

// Logs Warning if count is not greater than 0
logger.AssertWarning(items.Count > 0, "Processing an empty list");

The When Pattern

Explicitly log based on truthiness.

// Logs only when true
logger.InfoWhen(isNewUser, "Sending welcome email to {Email}", email);

// Logs only when false
logger.DebugWhenNot(isCacheHit, "Fetching data from remote API...");

Methods available for all levels: Trace, Debug, Info, Warn, Error, Critical.


๐Ÿงช Manual Initialization

If you are not using Dependency Injection, you can use the LoggerFactory directly:

using Serilog.Extensions.Services;

// Create a logger with default settings
var logger = LoggerFactory.New();

// Create a logger from a specific config file
var logger = LoggerFactory.New("path/to/config.json");

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

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 (4)

Showing the top 4 NuGet packages that depend on Serilog.Extensions:

Package Downloads
GN2.Business.Base

Provides a api library for business services.

Kmd.CqrsCore

Package Description

Zokhrof.Appbase.Messenger

Package Description

ItTitansGmbh.Utility.SeriLogSQLTranslator

SeriLogSQL Translator is a powerful and user-friendly tool designed to bridge the gap between SeriLog and SQL. Leveraging a robust parsing system, it transforms SeriLog log strings into executable SQL commands, eliminating the need for manual translation and making your database interactions more efficient and reliable.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.0.0 10,920 2/4/2026
9.1.0 27,667 11/8/2025
9.0.0 324 11/8/2025
8.1.0 147,917 6/16/2025
8.0.3 219,640 11/18/2024
8.0.2 48,420 9/13/2024
8.0.1 72,461 7/10/2024
8.0.0 53,105 1/18/2024
7.1.0 13,247 5/3/2024
7.0.0 4,420 1/28/2024
3.4.3 874 1/18/2024
3.4.2 19,329 8/17/2023
3.4.0 8,540 5/20/2023
3.3.1 2,601 3/14/2023
3.3.0 7,464 2/21/2023
3.2.2 1,103 2/21/2023
3.2.1 939 2/21/2023
3.2.0 1,086 2/5/2023
3.1.0 3,020 12/8/2022
3.0.0 1,397 11/25/2022
Loading failed