Sparkdo.AspNetCore.Serilog 1.0.1

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Sparkdo.AspNetCore.Serilog --version 1.0.1
                    
NuGet\Install-Package Sparkdo.AspNetCore.Serilog -Version 1.0.1
                    
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="Sparkdo.AspNetCore.Serilog" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sparkdo.AspNetCore.Serilog" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Sparkdo.AspNetCore.Serilog" />
                    
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 Sparkdo.AspNetCore.Serilog --version 1.0.1
                    
#r "nuget: Sparkdo.AspNetCore.Serilog, 1.0.1"
                    
#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 Sparkdo.AspNetCore.Serilog@1.0.1
                    
#: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=Sparkdo.AspNetCore.Serilog&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Sparkdo.AspNetCore.Serilog&version=1.0.1
                    
Install as a Cake Tool

Sparkdo.AspNetCore.Serilog

Sparkdo ASP.NET Core Serilog 集成库,提供与 Serilog 的无缝集成,支持在日志中添加租户、用户、客户端和关联ID等上下文信息。

功能特性

  • 与 Serilog 的无缝集成
  • 自动添加租户、用户、客户端和关联ID到日志上下文
  • 支持自定义属性名称
  • 与 Sparkdo 多租户、用户、客户端和追踪系统无缝集成
  • 支持 ASP.NET Core 中间件管道集成

安装

<PackageReference Include="Sparkdo.AspNetCore.Serilog" Version="x.x.x" />

核心组件

SparkdoSerilogMiddleware

Serilog 中间件,用于在 ASP.NET Core 请求处理管道中添加上下文信息到 Serilog 日志中:

  • 自动从当前请求上下文中提取租户、用户、客户端和关联ID
  • 将这些信息添加到 Serilog 日志上下文,使日志条目包含丰富的上下文信息

SparkdoAspNetCoreSerilogOptions

Serilog 配置选项,用于配置日志增强属性的名称:

  • EnricherPropertyNames.TenantId: 租户标识属性名(默认:"TenantId")
  • EnricherPropertyNames.UserId: 用户标识属性名(默认:"UserId")
  • EnricherPropertyNames.ClientId: 客户端标识属性名(默认:"ClientId")
  • EnricherPropertyNames.CorrelationId: 关联标识属性名(默认:"CorrelationId")

SparkdoAspNetCoreSerilogModule

Sparkdo 模块配置类,负责注册 Serilog 相关服务:

  • 注册 SparkdoSerilogMiddleware 中间件

扩展性

该库提供了完整的 Serilog 集成功能实现,可以通过以下方式扩展:

  1. 通过 SparkdoAspNetCoreSerilogOptions 自定义日志属性名称
  2. 实现自定义的中间件来添加额外的日志上下文信息

代码结构说明

本项目包含以下主要组件:

中间件

  • SparkdoSerilogMiddleware: Serilog 中间件实现

配置

  • SparkdoAspNetCoreSerilogOptions: Serilog 配置选项
  • SparkdoAspNetCoreSerilogModule: 模块配置

所有公共接口和类都添加了详细的 XML 文档注释,便于开发者理解和使用。

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
1.0.2-preview.4 36 2/8/2026
1.0.2-preview.3 51 2/1/2026
1.0.2-preview.2 43 1/31/2026
1.0.2-preview.1 159 12/4/2025
1.0.1 157 11/27/2025
1.0.0 155 11/25/2025
1.0.0-preview.5 114 10/24/2025