DropBear.Codex.AppLogger 2024.7.3

dotnet add package DropBear.Codex.AppLogger --version 2024.7.3                
NuGet\Install-Package DropBear.Codex.AppLogger -Version 2024.7.3                
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="DropBear.Codex.AppLogger" Version="2024.7.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DropBear.Codex.AppLogger --version 2024.7.3                
#r "nuget: DropBear.Codex.AppLogger, 2024.7.3"                
#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.
// Install DropBear.Codex.AppLogger as a Cake Addin
#addin nuget:?package=DropBear.Codex.AppLogger&version=2024.7.3

// Install DropBear.Codex.AppLogger as a Cake Tool
#tool nuget:?package=DropBear.Codex.AppLogger&version=2024.7.3                

DropBear.Codex.AppLogger

Description

DropBear.Codex.AppLogger is a flexible and configurable logging library designed to wrap around existing logging frameworks. It provides a fluent API for configuring logging behavior, including support for console and file outputs, custom log formats, and more. The library aims to make logging in .NET applications straightforward and adaptable.

Features

  • Fluent API for easy configuration
  • Supports console and file logging
  • Integrates with ZLogger and Serilog
  • Provides extension methods for easy setup with dependency injection containers
  • Dynamic logger configuration through runtime methods

Getting Started

To use DropBear.Codex.AppLogger in your project, start by configuring the logger factory according to your needs:

Basic Configuration

var loggerFactory = new LoggerConfigurationBuilder()
    .SetLogLevel(LogLevel.Information)
    .EnableConsoleOutput(true)
    .Build();
var logger = loggerFactory.CreateLogger<MyClass>();
logger.LogInformation("Hello, World!");

Advanced Configuration with File Logging

var loggerFactory = new LoggerConfigurationBuilder()
    .SetLogLevel(LogLevel.Debug)
    .EnableConsoleOutput(true)
    .UseJsonFormatter()
    .ConfigureRollingFileAsync("logs/", 1024).GetAwaiter().GetResult()
    .Build();
var logger = loggerFactory.CreateLogger<MyClass>();
logger.LogDebug("Debugging information.");

Using LoggerManager

LoggerManager is a singleton class that provides a centralized way to manage and retrieve loggers throughout your application. It ensures that only one instance of each logger is created and provides a mechanism for reconfiguring loggers at runtime.

Retrieving a Logger

var logger = LoggerManager.Instance.GetLogger<MyClass>();
logger.LogInformation("Managed logger instance ready to use.");

Reconfiguring Loggers at Runtime

LoggerManager allows you to dynamically change logger configurations, such as log levels or outputs. This can be especially useful in scenarios where logging behaviors need to be adjusted without restarting the application.

LoggerManager.Instance.ConfigureLogger(builder =>
{
    builder.SetLogLevel(LogLevel.Warning)
           .EnableConsoleOutput(false)
           .UseJsonFormatter(true)
           .ConfigureRollingFile("logs/", 2048);
});
var logger = LoggerManager.Instance.GetLogger<MyClass>();
logger.LogWarning("Logger configuration updated.");

This functionality supports dynamic environments and helps maintain flexibility in how applications log their activities.

Integration with ASP.NET Core

DropBear.Codex.AppLogger can be easily integrated into ASP.NET Core applications using the provided extension method:

public void ConfigureServices(IServiceCollection services)
{
    services.AddAppLogger(builder =>
    {
        builder.SetLogLevel(LogLevel.Information)
               .EnableConsoleOutput(true)
               .UseJsonFormatter()
               .ConfigureRollingFile("logs/", 1024);
    });
}

Warning

This code is under active pre-development and is subject to change. It may or may not work as expected and should be used with caution in production environments.

Contributing

We welcome contributions and suggestions! Please submit issues and pull requests on our GitHub repository for any features or bug fixes.

License

This project is licensed under the LGPLv3 License - see the LGPL-3.0 License for details.

Changes and Enhancements:

  • Features: Updated to include Serilog integration.
  • Getting Started: Updated code examples to reflect the latest implementation and changes.
  • Integration with ASP.NET Core: Ensured the example is accurate with the latest extension method.
  • Formatting: Ensured consistency and readability across the document.

Next Steps

  1. Unit Tests: Ensure that unit tests cover the examples provided in the README.
  2. Documentation: Keep the README updated with any new features or changes to the library.
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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.