LealLogger 1.0.0

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

LealLogger

LealLogger is a high-performance, extensible, and lightweight logging library for .NET applications. It supports multiple logging outputs (e.g., Console, File) and provides flexibility through a powerful builder pattern. Whether you're developing a small project or a high-load enterprise application, LealLogger adapts to your needs with ease.


Table of Contents

Getting Started

Installation

You can install LealLogger via terminal:

// TODO (I'll publish in Nuget package)

Nuget Package. TODO...

Usage

1. Basic Setup
using LealLogger.Factory;

using var logger = new LoggerBuilder()
    .AddConsoleHandler() // This adds a console handler to the logger, witch means that every time 
                        // you log something it will be automatically printed into the console
    .SetMinimumLogLevel(LogLevel.INFO)
    .Build();


logger.Debug("Application started."); // This won't be logged, because you setted the minimum LevelLog to INFO
logger.Info("Application started.");
logger.Warn("Low disk space detected.");
logger.Error("Unhandled exception occurred.", new Exception("Example exception"));
2. Adding File Logging
var logger = new LoggerBuilder()
    .AddConsoleHandler()
    .AddFileHandler("logs/app.log")
    .SetQueueCapacity(5000)
    .Build();

logger.Info("Logging to both console and file.");
3. Custom Logger

Define a custom logger class by inheriting from BaseLogger:

public sealed class MyCustomLogger : BaseLogger
{
    public MyCustomLogger(LogLevel logLevel, int queueCapacity, ImmutableArray<LogHandler> handlers)
        : base(logLevel, queueCapacity, handlers)
    {
    }

    public override void Debug(string message, Exception? ex = null) { /* Custom behavior */ }
    public override void Info(string message, Exception? ex = null) { /* Custom behavior */ }
    public override void Warn(string message, Exception? ex = null) { /* Custom behavior */ }
    public override void Error(string message, Exception? ex = null) { /* Custom behavior */ }
    public override void Fatal(string message, Exception? ex = null) { /* Custom behavior */ }
    public override void Dispose() { /* Cleanup resources */ }
}

Use the LoggerBuilder to instantiate it:

var customLogger = new LoggerBuilder()
    .AddConsoleHandler()
    .Build<MyCustomLogger>(); // <--

customLogger.Info("Custom logger in action!");

API Reference

LoggerBuilder

The LoggerBuilder class simplifies logger configuration and instantiation.

  • AddConsoleHandler(): Adds a console log handler.
  • AddFileHandler(string filePath): Adds a file log handler.
  • AddHandler<T>(T handler): Adds a custom log handler.
  • SetMinimumLogLevel(LogLevel logLevel): Sets the minimum log level for logs to be processed.
  • SetQueueCapacity(int queueCapacity): Sets the queue capacity for buffering logs.
  • Build(): Creates a default Logger.
  • Build<T>(): Creates a custom logger of type T.

Log Levels

  • DEBUG
  • INFO
  • WARN
  • ERROR
  • FATAL

LogHandler

Implement LogHandler to create custom log output mechanisms. For example:

public sealed class MyCustomHandler : LogHandler
{
    public override void HandleLog(Log logEntry)
    {
        // Custom handling logic
    }

    public override void Dispose()
    {
        // Cleanup resources
    }
}

Customization Guide

Custom Log Handlers

Create your own log handler by inheriting from LogHandler. Example:

public sealed class DatabaseLogHandler : LogHandler
{
    public override void HandleLog(Log logEntry)
    {
        // Insert log entry into a database
    }

    public override void Dispose()
    {
        // Close database connections
    }
}
var logger = new LoggerBuilder()
    .AddConsoleHandler()
    .AddFileHandler("logs/app.log")
    .AddHandler(new DatabaseLogHandler())
    .SetQueueCapacity(5000)
    .Build();

logger.Info("This log will be printed into the console, saved into the file and saved into the database");

Contribution

Contributions are welcome! If you have ideas to improve LealLogger, feel free to open an issue or fork the repository.

How to Contribute

  • Fork the repository.
  • Create a new branch for your feature or bugfix.
  • Please, test your changes before committing.
  • Submit a pull request with a detailed explanation of your changes.
  • 😃

License

This project is licensed under the MIT License. See the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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.
  • net9.0

    • No dependencies.

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
1.0.3 108 7/30/2025
1.0.2 103 1/16/2025
1.0.1 119 1/11/2025
1.0.0 113 1/9/2025