ZLogger  by Cysharp

Zero-allocation .NET/Unity logger

created 5 years ago
1,530 stars

Top 27.6% on sourcepulse

GitHubView on GitHub
Project Summary

ZLogger is a high-performance logging library for .NET and Unity, designed for zero-allocation and leveraging modern C# features like string interpolation and source generators. It integrates seamlessly with Microsoft.Extensions.Logging, offering significant performance gains by avoiding intermediate string allocations and UTF-16 to UTF-8 encoding overhead.

How It Works

ZLogger utilizes C# 10's interpolated string handlers and .NET 8's IUtf8SpanFormattable to directly format log messages into UTF-8 byte spans. This bypasses the boxing of values and the creation of intermediate string objects, leading to substantial performance improvements. By integrating directly with Microsoft.Extensions.Logging's abstraction, it eliminates the overhead typically associated with bridging different logging systems.

Quick Start & Requirements

  • Installation: dotnet add package ZLogger
  • Prerequisites: .NET 6+ recommended for full features; .NET Standard 2.0/2.1 supported. Unity 2022.2+ required for Unity integration, with Unity 2022.3.12f1+ recommended for source generator support. Requires csc.rsp configuration for C# 10/11 features in Unity.
  • Usage: Integrate via WebApplication.CreateBuilder().Logging.AddZLoggerConsole(); or LoggerFactory.Create(logging => logging.AddZLoggerConsole());.
  • Docs: Getting Started

Highlighted Details

  • Zero-allocation logging via UTF-8 span formatting.
  • Supports text and structured (JSON) logging with customizable formatters.
  • Includes a source generator for compile-time log message creation.
  • Offers various output providers: Console, File, RollingFile, Stream, InMemory.
  • Compatible with .NET Standard 2.0, .NET 6+, and Unity.

Maintenance & Community

  • Developed by Cysharp, known for high-performance .NET libraries.
  • Active development and community support.

Licensing & Compatibility

  • MIT License. Permissive for commercial use and integration with closed-source applications.

Limitations & Caveats

  • Full C# 10/11 feature utilization requires specific .NET versions or Unity configurations.
  • Unity integration requires manual compiler flag setup (csc.rsp) and potentially NuGetForUnity and CsprojModifier.
Health Check
Last commit

2 months ago

Responsiveness

Inactive

Pull Requests (30d)
2
Issues (30d)
1
Star History
112 stars in the last 90 days

Explore Similar Projects

Feedback? Help us improve.