Vane.Logging 1.0.0

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

Vane.Logging

轻量、高性能的 .NET 日志组件库,零外部依赖。派发模型沿用 logger → appender → layout 三段式,底层换成结构体日志条目、零分配渲染与源生成器。

版本 1.0.0 · 目标框架 .NET 8.0 / 10.0 / 11.0 · 许可证 MIT 源码仓库:https://gitee.com/netcasewqs/vane.logging

特性

  • 零分配渲染 —— LogEntry 值语义结构体 + 栈缓冲 / ArrayPool 复用,热路径不产生 GC
  • 零装箱派发 —— 源生成器把结构化参数装进泛型参数袋,穿过整条派发链
  • 源生成器双后端 —— [Log] 注入 ILog 字段,[LoggerMessage] 生成强类型方法,一份声明同时适配本库与 Microsoft.Extensions.Logging
  • 结构化输出 —— JSON / CLEF 单行直出,JSON 键名可对齐 ECS / OTel
  • 9 种 Appender —— Console、Debug、Trace、None、File、AsyncFile、Udp、AdoNet、BufferWriter
  • 8 种过滤器 + 11×6 滚动 —— 级别、前缀、正则、属性等组合过滤;文件滚动 11 种模式、目录滚动 6 种模式(另有 None 表示不按目录拆分)
  • 跨进程共享写 —— 多进程写同一文件按行原子追加,不会互相穿插
  • 编译期诊断 —— LLG0001–LLG0016 覆盖装载入口、布局模式与高开销插值

快速开始

安装

dotnet add package Vane.Logging          # 锁定版本时加 --version 1.0.0

# 接入 ASP.NET Core / Microsoft.Extensions.Logging 时再加
dotnet add package Vane.Logging.Mel

源生成器随包以 Analyzer 形式自动引入,无需单独安装。核心 API 在 Vane.Logging;代码内配置(AppenderFactory、LogManagerOptions)在 Vane.Logging.Options,过滤器在 Vane.Logging.Options.Filtering,MEL 扩展在 Vane.Logging.Mel。

五行开始记录

using Vane.Logging;

LogManager.InitializeFromFile();                 // 读 log.config.xml;无配置则丢弃日志,不落盘不报错
var log = LogManager.GetLogger<Program>();
log.Info("应用启动");
LogManager.Shutdown();                            // 退出前调用,排空异步缓冲

GetLogger<T>() 的 Logger 名取类型全限定名;需要自定义名字时用 LogManager.GetLogger("Order.Service")。

源生成器:声明一次,方法自动生成

using Vane.Logging;

[Log]
public partial class OrderService
{
    public void Create(int orderId) =>
        log.InfoFormat("订单创建 {0}", orderId);          // 字段 log 由生成器注入

    // [LoggerMessage] 由方法名推断级别,生成带级别短路与零装箱参数的实现
    [LoggerMessage(LogLevel.Warn, "慢查询 {Sql} 耗时 {Elapsed}ms")]
    public partial void LogSlowQuery(string sql, long elapsed);
}

走项目引用而非 NuGet 包时,源生成器不会自动传递,消费方需自挂 <ProjectReference … OutputItemType="Analyzer" ReferenceOutputAssembly="false" />,否则 [LoggerMessage] 会报 CS8795。

配置文件

默认读取程序目录下的 log.config.xml,缺失时按 xml → json → ini 探测同名配置;也支持环境变量与纯代码配置。

<?xml version="1.0" encoding="utf-8"?>
<log SupportsExpiredFileDetector="true" ExpiredFileCheckInterval="30">
  <Appenders>
    <Appender Type="Console" Name="console" Level="Info" />
    <Appender Type="File" Name="file" Level="Debug">
      <File FileDirectory="Logs" FileName="app" Extension=".log"
            RollingMode="DailyAndSize" MaxFileSize="50" ExpiredDays="30" />
    </Appender>
  </Appenders>
  <Loggers>
    <Logger Name="MyApp.Data" Level="Debug">
      <Appenders><Appender>file</Appender></Appenders>
    </Logger>
  </Loggers>
  <Root Level="Warn">
    <Appenders><Appender>console</Appender></Appenders>
  </Root>
</log>

Pattern 布局共 26 个占位符(其中 %literal 由解析器内部使用,可手写 25 个;%timestamp、%level、%logger、%message、%exception …),%% 转义为字面量 %,支持 [%-5level] 这类对齐修饰。

文档

文档 内容
使用手册 核心概念 / 配置详解 / Appender 全属性 / 占位符全表 / 源生成器 / 性能设计 / 选型对比 / log4net 迁移
配置参考 加载机制 / 三格式完整示例 / Schema 校验 / 已知限制
MEL 集成指南 注册 API 全景 / 生命周期 / 级别与名称映射 / Scope / 热重载
编译期诊断码 LLG0001–LLG0016 逐条说明与触发条件
MiniLog 迁移指南 旧包更名的对照表与迁移自检
基准报告 与 NLog / Serilog / log4net / MS Logging 的横向数据
变更日志 1.0.0 首发记录

从源码构建

dotnet build Vane.Logging.slnx -c Release
dotnet test  Vane.Logging.slnx -c Release
dotnet pack  src/Vane.Logging/Vane.Logging.csproj -c Release

核心库与生成器开启 TreatWarningsAsErrors,三个 TFM(net8.0 / net10.0 / net11.0)要求 0 警告 0 错误。发版流程见 RELEASE.md。

许可证

MIT,见 LICENSE。

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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 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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net11.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Vane.Logging:

Package Downloads
Vane.Logging.Mel

Microsoft.Extensions.Logging adapter for Vane.Logging, enabling Vane.Logging as a logging provider in ASP.NET Core and generic-host applications.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 109 11/19/2026

First public release of Vane.Logging, published as 1.0.0. Public API is backward compatible from this version. Core API carries no Vane prefix; Vane appears as the namespace root only. Microsoft.Extensions.Logging integration ships separately as Vane.Logging.Mel (AddVaneLog / AddVaneLogManager). Analyzer diagnostics cover LLG0001 through LLG0016, including layout pattern validation and expensive interpolation argument warnings. Config keys use the Vane.Logging.* prefix and the Vane.Logging config section. Includes structured output, source generators, buffer writer appenders, cross process shared file writes, and nine appenders. The VanePack binary formatter is an optional experimental extension and is not part of this release. See CHANGELOG.md.