CodeWF.Log.Core 11.3.15

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

CodeWF.Log

NuGet NuGet NuGet NuGet License

轻量级、高性能 .NET 日志库,支持控制台和 Avalonia UI 应用程序。

两个 NuGet 包

包名 说明 适用场景
CodeWF.Log.Core 核心日志库,仅依赖 .NET 控制台程序、WPF、Avalonia 等所有 C# 程序
CodeWF.LogViewer.Avalonia Avalonia UI 控件,依赖 CodeWF.Log.Core Avalonia UI 程序,提供日志展示控件

CodeWF.Log.Core

核心日志库,NuGet 包安装:

Install-Package CodeWF.Log.Core

基本使用

Logger.Debug("调试日志");
Logger.Info("普通日志");
Logger.Warn("警告日志");
Logger.Error("错误日志");
Logger.Fatal("严重错误日志");

控制台程序初始化(重要)

控制台程序使用文件日志时,需要在启动时初始化:

// Program.cs 或 Main 方法中调用一次
Logger.RecordToFile();

// 程序退出时刷新缓冲区
await Logger.FlushAsync();

日志输出目标控制

每个日志方法支持参数控制输出目标:

Logger.Info(
    content: "写入文件的内容",
    uiContent: "UI显示的友好内容",  // 可选,默认为null,此时UI显示content参数的内容
    log2UI: true,       // 是否输出到UI
    log2File: true,      // 是否输出到文件
    log2Console: true    // 是否输出到控制台
);

// 快捷方法
Logger.InfoToFile("仅写入文件");           // log2UI=false, log2Console=false
Logger.LogToUI(LogType.Info, "仅显示UI");  // log2File=false

配置参数

Logger.Level = LogType.Info;                    // 日志级别,低于此级别的日志被忽略
Logger.LogDir = "/path/to/logs";                // 日志文件存储目录
Logger.BatchProcessSize = 200;                  // 批量写入的日志条数阈值
Logger.MaxLogFileSizeMB = 500;                   // 单个日志文件最大大小(MB)
Logger.EnableConsoleOutput = true;               // 是否输出到控制台

CodeWF.LogViewer.Avalonia

Avalonia UI 日志展示控件,NuGet 包安装:

Install-Package CodeWF.LogViewer.Avalonia

XAML 使用

xmlns:log="https://codewf.com"
<log:LogView />

Avalonia 程序初始化

// 程序退出时调用
await Logger.FlushAsync();

注意:LogView 控件内部会自动调用 RecordToFile() 启动文件日志记录,并从 UI 通道消费日志显示到界面。

日志消费

LogView 内部使用 await foreach 异步枚举模式消费 UI 通道日志,支持批量处理和防抖机制:

  • 日志数量达到 BatchProcessSize 时立即刷新 UI
  • 未达阈值时,最长延迟 LogUIDuration(默认100ms)后刷新

更新日志

V1.0.12(2026-04)

  1. ✨[优化]-重构为 Channel 架构,提升性能
  2. ✨[优化]-添加防抖机制,避免日志频繁刷新
  3. ✨[优化]-UI消费使用 await foreach 异步枚举模式
  4. 🐛[修复]-修复 FlushAsync 方法

V1.0.11.3(2025-09-15)

  1. 🐛[修复]-修复自定义日志目录打开异常问题

TODO

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.
  • net10.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on CodeWF.Log.Core:

Package Downloads
CodeWF.LogViewer.Avalonia

自定义 Avalonia 日志组件​ 专为 Avalonia 打造的日志组件,支持将日志同步写入本地文件与 SelectedTextBlock 控件,实现持久化存储与实时界面展示,助力高效调试。​ Custom Avalonia Log Component​ A log component tailored for Avalonia. It supports synchronously writing logs to local files and the SelectedTextBlock control, enabling persistent storage and real-time interface display for efficient debugging.

CodeWF.NetWrapper

CodeWF.NetWrapper builds on CodeWF.NetWeaver and provides TCP/UDP helpers, command dispatching, and file transfer or file management capabilities.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
12.0.2.1 119 5/7/2026
12.0.2 106 4/30/2026
11.3.15 106 4/27/2026
11.3.14 140 4/17/2026
11.3.12.2 120 3/17/2026
11.3.12.1 140 2/13/2026
11.3.10 244 12/25/2025
11.3.9.8 260 12/15/2025
11.3.9.7 190 12/12/2025
11.3.9.4 187 11/29/2025
11.3.9.2 227 11/25/2025