Serilog.Extensions
10.0.0
dotnet add package Serilog.Extensions --version 10.0.0
NuGet\Install-Package Serilog.Extensions -Version 10.0.0
<PackageReference Include="Serilog.Extensions" Version="10.0.0" />
<PackageVersion Include="Serilog.Extensions" Version="10.0.0" />
<PackageReference Include="Serilog.Extensions" />
paket add Serilog.Extensions --version 10.0.0
#r "nuget: Serilog.Extensions, 10.0.0"
#:package Serilog.Extensions@10.0.0
#addin nuget:?package=Serilog.Extensions&version=10.0.0
#tool nuget:?package=Serilog.Extensions&version=10.0.0
Serilog Extensions for .NET
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 | Versions 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. |
-
net10.0
- Json.AspNetCore (>= 9.0.0)
- Microsoft.Extensions.Configuration (>= 10.0.2)
- Microsoft.Extensions.Configuration.Json (>= 10.0.2)
- Newtonsoft.Json (>= 13.0.4)
- Serilog.AspNetCore (>= 10.0.0)
- Serilog.Enrichers.Environment (>= 3.0.1)
- Serilog.Enrichers.Process (>= 3.0.0)
- Serilog.Enrichers.Thread (>= 4.0.0)
- Serilog.Expressions (>= 5.0.0)
- Serilog.Extensions.Logging (>= 10.0.0)
-
net7.0
- Json.AspNetCore (>= 9.0.0)
- Microsoft.Extensions.Configuration (>= 7.0.0)
- Microsoft.Extensions.Configuration.Json (>= 7.0.0)
- Newtonsoft.Json (>= 13.0.4)
- Serilog.AspNetCore (>= 7.0.0)
- Serilog.Enrichers.Environment (>= 3.0.1)
- Serilog.Enrichers.Process (>= 3.0.0)
- Serilog.Enrichers.Thread (>= 4.0.0)
- Serilog.Expressions (>= 5.0.0)
- Serilog.Extensions.Logging (>= 7.0.0)
-
net8.0
- Json.AspNetCore (>= 9.0.0)
- Microsoft.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.Configuration.Json (>= 8.0.1)
- Newtonsoft.Json (>= 13.0.4)
- Serilog.AspNetCore (>= 8.0.3)
- Serilog.Enrichers.Environment (>= 3.0.1)
- Serilog.Enrichers.Process (>= 3.0.0)
- Serilog.Enrichers.Thread (>= 4.0.0)
- Serilog.Expressions (>= 5.0.0)
- Serilog.Extensions.Logging (>= 8.0.0)
-
net9.0
- Json.AspNetCore (>= 9.0.0)
- Microsoft.Extensions.Configuration (>= 9.0.12)
- Microsoft.Extensions.Configuration.Json (>= 9.0.12)
- Newtonsoft.Json (>= 13.0.4)
- Serilog.AspNetCore (>= 9.0.0)
- Serilog.Enrichers.Environment (>= 3.0.1)
- Serilog.Enrichers.Process (>= 3.0.0)
- Serilog.Enrichers.Thread (>= 4.0.0)
- Serilog.Expressions (>= 5.0.0)
- Serilog.Extensions.Logging (>= 9.0.2)
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 |