Skip to content

A simple and flexible logging library for .NET applications.

License

Notifications You must be signed in to change notification settings

NovemoG/Novelog

Repository files navigation

Novelog

Novelog is a simple and flexible logging library for .NET applications. It supports multiple log handlers, message enrichment, and formatting.

Features

  • Log to multiple handlers (e.g., console, file)
  • Rolling file log handler with size-based rotation
  • Custom log handlers

Installation

To install Novelog, add the following NuGet package to your project:

dotnet add package Novelog

Usage

Basic Configuration

To use the logger, you need to configure it first. You can configure the logger using Dependency Injection (DI) or manually. The shared logger instance will be set up automatically when using either method.

Using Dependency Injection

  1. Add the logger to your service collection Program.cs:
using Microsoft.Extensions.DependencyInjection;
using Novelog;

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddLogger(config =>
        {
            config.AttachConsole();
        });
    }
}
  1. Inject and use the logger in your classes:
using Novelog;

public class MyClass
{
    private readonly ILogger _logger;

    public MyClass(ILogger logger)
    {
        _logger = logger;
    }

    public void DoSomething()
    {
        _logger.LogInfo("This is an info message.");
    }
}

Manual Configuration

  1. Configure the logger manually:
using Novelog;
using Novelog.Config;

var logger = new LoggerConfigBuilder()
    .AttachConsole()
    .Build();
  1. Use the shared logger:
using Novelog;

public class MyClass
{
    public void DoSomething()
    {
        Logger.Shared.LogInfo("This is an info message.");
    }
}

Rolling File Log Handler

The rolling file log handler rotates log files based on size. Configure it using the RollingFileConfig class:

using Novelog.Config;

var rollingFileConfig = new RollingFileConfig
{
    FilePath = "logs/log.txt",
    MaxFileSize = 10 * 1024 * 1024,
    MaxFileCount = 5,
    MinLogLevel = LogLevel.INFO
};

var logger = new LoggerConfigBuilder()
    .AttachRollingFile(rollingFileConfig)
    .Build();

License

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

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

About

A simple and flexible logging library for .NET applications.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages