CodeOfChaos.Extensions.AspNetCore 0.27.0

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

// Install CodeOfChaos.Extensions.AspNetCore as a Cake Tool
#tool nuget:?package=CodeOfChaos.Extensions.AspNetCore&version=0.27.0                

CodeOfChaos.Extensions.AspNetCore

CodeOfChaos.Extensions.AspNetCore is a lightweight library that simplifies some aspects of ASP.NET Core applications.


Features

Simplified Serilog Integration

  • Easily replaces the default ASP.NET Core logging with Serilog.
  • Supports custom configuration via LoggerConfiguration for full control over your logging setup.
  • Automatically manages Serilog's lifecycle, ensuring proper cleanup on application shutdown.

Installation

This library targets .NET 9.0 and requires C# 13.0. Ensure your project meets these requirements before using.

Add the dependency to your project via NuGet:

dotnet add package CodeOfChaos.Extensions.AspNetCore

Usage

Here's how you can use the library to configure Serilog in your ASP.NET Core application:

Example Setup

  1. Install the CodeOfChaos.Extensions.AspNetCore package in your project.

  2. Modify your Program.cs or Startup.cs file:

    using CodeOfChaos.Extensions.AspNetCore;
    using Serilog;
    
    var builder = WebApplication.CreateBuilder(args);
    
    // Override logging with Serilog
    builder.OverrideLoggingWithSerilog(configure: config =>
    {
        config.WriteTo.Console(); // Example: Log to console
    });
    
    var app = builder.Build();
    
    app.Run();
    
  3. Run your application. Serilog will now be the active logging provider.


Features in Detail

Method: OverrideLoggingWithSerilog

This method replaces the default logging system with Serilog. It provides several key capabilities:

  • Accepts an optional configuration delegate to customize LoggerConfiguration (e.g., specifying sinks like Console, File, etc.).
  • Integrates all required services and clears default logging providers automatically.
  • Ensures proper flushing and cleanup of logs using an internally managed hosted service on application shutdown.

Contributing

Feel free to fork and contribute to the project by submitting pull requests. When contributing, ensure your changes align with the project’s coding standards.

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

Version Downloads Last updated
0.27.0 42 12/29/2024
0.26.0 53 12/28/2024
0.25.0 49 12/28/2024
0.24.3 49 12/27/2024
0.24.2 38 12/27/2024
0.24.1 36 12/27/2024
0.24.0 41 12/27/2024
0.23.1 38 12/27/2024
0.23.0 39 12/27/2024
0.22.2 42 12/27/2024
0.22.0 78 12/23/2024
0.21.0 82 12/22/2024
0.20.0-preview.1 42 12/21/2024
0.2.1 104 10/31/2024
0.2.0 96 10/5/2024
0.1.3 134 8/30/2024
0.1.2 135 7/1/2024
0.1.1 147 6/13/2024
0.1.0 153 6/7/2024