Projects

CodeWF.LogViewer

Lightweight logging library and Avalonia log viewer control

Documentation

CodeWF.LogViewer

CodeWF.LogViewer

CodeWF.LogViewer includes a lightweight logging core library and an Avalonia UI log display control. The core package can be used in console, WPF, WinForms, Avalonia, and other C# programs; the Avalonia control is responsible for displaying logs in real time on the UI, suitable for desktop application debugging and tool-based clients.

NuGet Packages

Package Description Use Case
CodeWF.Log.Core Core logging library, only depends on .NET. Console, WPF, WinForms, Avalonia, etc. C# programs.
CodeWF.LogViewer.Avalonia Avalonia UI log display control. Embedded log window in Avalonia UI applications.

Installation

Install-Package CodeWF.Log.Core
Install-Package CodeWF.LogViewer.Avalonia

Basic Usage

Logger.Debug("Debug log");
Logger.Info("Info log");
Logger.Warn("Warning log");
Logger.Error("Error log");
Logger.Fatal("Fatal error log");

When using file logging in a console application, it is recommended to handle the file channel on startup and exit:

Logger.RecordToFile();

// Flush buffer on program exit
await Logger.FlushAsync();

Output Target Control

Each log method can control whether to output to UI, file, and console:

Logger.Info(
    content: "Content written to file",
    uiContent: "User-friendly content for UI",
    log2UI: true,
    log2File: true,
    log2Console: true);

You can also use shortcut methods:

Logger.InfoToFile("Write to file only");
Logger.LogToUI(LogType.Info, "Display UI only");

Avalonia Control

Import the namespace and place the control in AXAML:

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

LogView internally starts file logging and consumes logs from the UI channel to display them on the interface. For high-frequency logging scenarios, the control uses batch processing and debounce refresh to avoid frequent UI redraws.

Repository