CodeWF.LogViewer.Avalonia 12.0.2

dotnet add package CodeWF.LogViewer.Avalonia --version 12.0.2
                    
NuGet\Install-Package CodeWF.LogViewer.Avalonia -Version 12.0.2
                    
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.LogViewer.Avalonia" Version="12.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CodeWF.LogViewer.Avalonia" Version="12.0.2" />
                    
Directory.Packages.props
<PackageReference Include="CodeWF.LogViewer.Avalonia" />
                    
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.LogViewer.Avalonia --version 12.0.2
                    
#r "nuget: CodeWF.LogViewer.Avalonia, 12.0.2"
                    
#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.LogViewer.Avalonia@12.0.2
                    
#: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.LogViewer.Avalonia&version=12.0.2
                    
Install as a Cake Addin
#tool nuget:?package=CodeWF.LogViewer.Avalonia&version=12.0.2
                    
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.  net11.0 is compatible. 
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
12.0.2 34 4/30/2026
11.3.15 89 4/27/2026
11.3.14 100 4/17/2026
11.3.12.2 112 3/17/2026
11.3.12.1 113 2/13/2026
11.3.10 219 12/25/2025
11.3.9.8 247 12/15/2025
11.3.9.7 157 12/12/2025
11.3.9.4 152 11/29/2025
11.3.9.2 221 11/25/2025
11.3.9.1 192 11/23/2025
11.3.9 237 11/22/2025
1.1.0.1 308 11/12/2025
1.1.0 243 10/23/2025
1.0.11.5 206 10/14/2025
1.0.11.4 612 9/16/2025
1.0.11.3 258 9/15/2025
1.0.11.2 233 9/4/2025
1.0.11.1 225 8/4/2025
1.0.11 240 7/10/2025
Loading failed