Cangming.Logs.Contracts 0.1.10.1124

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

Cangming.Logs.Contracts

日志领域的对外契约层(netstandard2.0),定义不绑定任何日志框架的公共语言:ILogService 日志流服务接口、LogEntry 流载荷、LogSeverity 有序级别枚举、LogPartition 路由位掩码,以及分区路由的键名与模式常量。本工程处于依赖链最底端,不依赖任何组织内包与第三方框架包,因此任何宿主(Orbit/Mercury/插件进程)与任何日志实现(NLog/测试适配器)都以本工程为交汇点,而不互相引用。

包版本由仓库根 Directory.Build.props 统一控制,项目内不覆盖。

快速接线(AI 阅读)

当你要在本工程之上消费日志流时,按以下路径接线,禁止绕过契约直接耦合具体实现:

flowchart LR
    A["宿主业务代码"] -->|"LogHub(MEL 门面)"| B["NLog 管线"]
    B --> C["CompressingFileTarget<br/>归档落盘"]
    B --> D["LogEntryTarget<br/>(Cangming.Logs.NLog)"]
    D -->|"Write(LogEntry)"| E["ILogService<br/>(本契约)"]
    E -->|"Subscribe(admission, sink)"| F["订阅方:UI 集合 / 监控 / 转发"]
  • 消费日志流:引用本工程,向 ILogService.Subscribe(admission, sink) 传入谓词与接收委托,返回的 IDisposable 即退订手柄;级别过滤直接写 entry.Level >= LogSeverity.Warning,因为 LogSeverity 是有序枚举,不要比较字符串。
  • 生产日志流:实现 ILogService(默认实现见 Cangming.Logs 的 DefaultLogService),并保证两条不变量——线程安全、Write 不抛出(单个订阅者或谓词的异常由实现就地吞掉,不得回传写入方)。
  • 载荷 LogEntry 是 readonly record struct;SequenceId 优先取宿主写入的 cangming.seq,服务只在 0 时补号,文件与面板因此同源;Properties 是可空扩展槽,只有在“无结构化字段、无 trace 上下文、无宿主键”时才为 null——宿主一旦写 cangming.seq/cangming.session,每条都会带字典开销;槽内禁止塞入宿主业务语义。
  • v2 新增三项身份与字段信息,全部是 init 属性而非位置成员:Fields(LogFields 冻结快照,构造前由 LogFieldsBuilder 累积)、Source(LogSource 的包名/版本/插件标识,宿主按类别缓存复用)与 SessionId(与 cangming.session 同源);相等语义按 ADR-0017 D3 混合比较——九个位置成员按值(Exception 与 Properties 按引用)、Fields 按值逐项、Source 按引用、SessionId 按序数区分大小写。
  • LogPartition 是 ulong 位掩码,基础库只定义 None/All 一元,业务分区(Motion/Runtime 等)由消费方仓库从 bit0 起自行定义常量,谓词以 (entry.PartitionMask & Xxx) != 0 消费。
  • LogRouteMode 只有 WithMain / SkipMain 两个值,默认 WithMain;LogEntry.RouteMode 追加在位置参数末尾,8 参兼容构造保留但八个参数全部必填。
  • PartitionKeys 提供四个保留键与三个线上取值;LogHostKeys 提供 cangming.seq / cangming.session 两个宿主键。业务字段不得占用这些键。

分区路由示例

Cangming.Logs.Contracts 只提供 LogPartition 类型与 None/All 两个一元值;业务分区(LogPartitions.Motion 等)由消费方在自己那层定义并缓存:

// 宿主侧封装:装配期解析一次,之后热路径不查表
public static class LogPartitions
{
    public static LogPartition Motion { get; private set; }
    public static void Refresh() => Motion = PartitionRegistry.ResolveOrNone("Motion");
}

// 默认入口只写主日志
logger.LogInformation("普通消息");

// 追加功能分区;多个 To 按位或累积,条目仍交给 MEL 原生方法书写
logger.To(LogPartitions.Motion).LogInformation("运动消息");
logger.To(LogPartitions.Motion).To(LogPartitions.Runtime).LogInformation("多分区消息");

// 跳过默认/全量轨,仍写分区轨与错误轨
logger.To(LogPartitions.Connection).SkipMain().LogInformation("高频消息");

// 条件门控
logger.When(isVerbose).To(LogPartitions.Runtime).LogInformation("详细消息");

同族项目

项目 角色
Cangming.Logs 契约默认实现(DefaultLogService)+ LogHub MEL 门面 + 路由装饰器 + 作用域/限流/导出
Cangming.Logs.NLog 生产环境落地(NLog Target / 转换 / 分区过滤 / 序号 Target)
Cangming.Logs.xUnit 测试环境落地(MEL → ITestOutputHelper)
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Cangming.Logs.Contracts:

Package Downloads
Cangming.Logs

日志领域的基础实现。

Cangming.Logs.Testing

为插件测试提供 ILogService 的内存捕获实现与日志条目断言,只依赖 Contracts,不依赖具体日志框架与测试框架。

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.10.1124 55 11/24/2026
0.1.9.1122 243 11/22/2026
0.1.8.1117 226 11/17/2026
0.1.7.1116 225 11/16/2026
0.1.6.1109 230 11/9/2026
0.1.5.1105 234 11/5/2026
0.1.4.1105 235 11/5/2026
0.1.3.1102 244 11/2/2026
0.1.2.1029 740 10/29/2026
0.1.1.1028 189 10/28/2026

见仓库根 CHANGELOG.md