FormatLog 1.0.7

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

FormatLog Logging Component Solution

Language Switch

English | 简体中文

NuGet NuGet Downloads License: MIT GitHub stars

Solution Overview

This solution contains two projects:

  • FormatLog: A high-performance structured logging component supporting parameterization, format deduplication, caller context, batch writing, and cursor-based pagination queries.
  • DemoWPF: A WPF demo project showcasing log writing, querying, rich text rendering, and more.

FormatLog Component Core

Main Features

  • Structured Log Format: Unique constraint via Format, parameterized log content for easy search and analysis.
  • Parameterized Logging: Log supports up to 10 parameters, auto-archives parameter table to avoid duplicate storage.
  • Caller Context Tracking: CallerInfo records member, file, and line number for easy location.
  • High-Performance Batch Writing: FLog uses double-buffered queue + background thread, auto batch writes to SQLite, auto flush on process exit.
  • Efficient Pagination Query: Supports cursor pagination, bidirectional paging, and conditional filtering (level, time, format, parameters, caller, etc.).
  • Exception Persistence: Flush exceptions are automatically saved as JSON/TXT for troubleshooting.

Component Structure

  • FormatLog/Format.cs: Log format definition, uniqueness constraint, batch SQL insert.
  • FormatLog/Log.cs: Main log entity, includes format, parameters, caller context, creation time, etc.
  • FormatLog/Argument.cs: Log parameter entity, uniqueness constraint.
  • FormatLog/CallerInfo.cs: Caller context entity, uniqueness constraint.
  • FormatLog/LogDbContext.cs: EF Core database context, auto table creation, daily database partitioning.
  • FormatLog/FLog.cs: Log pool management, batch writing, exception handling, pagination query.
  • Other helper classes: QueryModel, FlushInfo, KeysetPage.

Quick Start

  1. Write log
FLog.Add(new Log(LogLevel.Info, "User login: {0}@{1}", userName, domain).WithCallerInfo());
  1. Query logs (pagination, filtering)
var query = new QueryModel()
    .WithLevel(LogLevel.Info)
    .WithFormat("Login")
    .OrderBy(OrderType.OrderByIdDescending)
    .WithNextCursorTick(nextCursorTick);

var page = await query.KeysetPaginationAsync();

Design Highlights

  • Format Deduplication: Log format, parameters, and caller context are automatically deduplicated to save storage.
  • Batch Efficiency: Double-buffered queue + batch SQL insert greatly improves write performance.
  • Easy Extension: Supports custom filtering, pagination, and exception handling.
  • Database Partitioning: Daily partitioning for easy archiving and maintenance.

Application Scenarios

  • Desktop/server applications with high-concurrency log writing
  • Structured log analysis and search systems
  • Debugging/operation scenarios requiring caller context and parameter tracking

Dependencies

  • .NET 8
  • Microsoft.EntityFrameworkCore.Sqlite

DemoWPF Demo Project

Main Features

  • Log Writing Demo: Supports batch writing of various log types (system info, multiplication, division, random string, long/short text, timestamp, user/disk/network info, etc.).
  • Log Query & Filtering: Supports multi-condition filtering by format, parameters, caller, level, time range, etc.; supports cursor pagination and bidirectional paging.
  • Rich Text Rendering: Log content parameters are highlighted, supports segmented rich text.
  • Performance Statistics: Real-time display of log write performance (time per 100 entries).

Main Interfaces

  • Log Writing Page: Select log type and level, batch write demo.
  • Log Query Page: Multi-condition filtering, paginated browsing, rich text highlighting.

How to Run

  1. Install .NET 8 SDK.
  2. Run the DemoWPF project (WinExe, WPF).
  3. Depends on MahApps.Metro (UI beautification), FormatLog (logging core).

Integrate FormatLog Steps

  1. Reference the FormatLog project or NuGet package.
  2. Use FLog.Add(new Log(...).WithCallerInfo()) to write logs.
  3. Use QueryModel for pagination queries.
  4. WPF can use LogViewModel for segmented rich text rendering.

Directory Structure

FormatLog/
  ├─ Format.cs
  ├─ Log.cs
  ├─ Argument.cs
  ├─ CallerInfo.cs
  ├─ LogDbContext.cs
  ├─ FLog.cs
DemoWPF/
  ├─ LogViewModel.cs
  ├─ LogTextSegment.cs
  ├─ MainWindow.xaml(.cs)

Dependencies

  • .NET 8
  • Microsoft.EntityFrameworkCore.Sqlite
  • MahApps.Metro (DemoWPF UI)

FAQ

  • Log write exceptions are automatically persisted to JSON/TXT files for troubleshooting.
  • Log database is partitioned daily for easy archiving and maintenance.

For detailed API documentation or secondary development advice, please refer to the source code comments or contact the maintainer.

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on FormatLog:

Package Downloads
EFCoreLayerKit

基于 Entity Framework Core 的通用数据访问层工具包,支持自动仓储注册、DTO 映射、软删除、自动迁移等,适用于 .NET 8+ 项目。

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.7 145 7/27/2025
1.0.6 268 7/26/2025
1.0.5 517 7/23/2025
1.0.4 513 7/22/2025
1.0.3 130 7/17/2025
1.0.2 118 7/17/2025
1.0.1 122 7/17/2025
1.0.0 126 7/16/2025