RA.Utilities.Logging.Core 10.0.0-rc.2

Prefix Reserved
This is a prerelease version of RA.Utilities.Logging.Core.
dotnet add package RA.Utilities.Logging.Core --version 10.0.0-rc.2
                    
NuGet\Install-Package RA.Utilities.Logging.Core -Version 10.0.0-rc.2
                    
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="RA.Utilities.Logging.Core" Version="10.0.0-rc.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RA.Utilities.Logging.Core" Version="10.0.0-rc.2" />
                    
Directory.Packages.props
<PackageReference Include="RA.Utilities.Logging.Core" />
                    
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 RA.Utilities.Logging.Core --version 10.0.0-rc.2
                    
#r "nuget: RA.Utilities.Logging.Core, 10.0.0-rc.2"
                    
#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 RA.Utilities.Logging.Core@10.0.0-rc.2
                    
#: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=RA.Utilities.Logging.Core&version=10.0.0-rc.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=RA.Utilities.Logging.Core&version=10.0.0-rc.2&prerelease
                    
Install as a Cake Tool

<p align="center"> <img src="../../Assets/Images/logging.svg" alt="RA.Utilities.Logging.Core Logo" width="128"> </p>

RA.Utilities.Logging.Core

NuGet version

RA.Utilities.Logging.Core provides a set of opinionated helpers and configurations for setting up structured logging with Serilog in .NET applications. This package simplifies the integration of common sinks (Console, File), enrichers (Exceptions, Sensitive Data), and performance features like asynchronous logging, enabling a robust and consistent logging strategy out of the box.

Purpose

Setting up a comprehensive logging solution from scratch can be repetitive. This package abstracts away the boilerplate configuration for Serilog by providing a single extension method, AddRaSerilog, that configures a production-ready logger with sensible defaults.

Key Features Configured by Default:

  • Structured Logging: Logs are written in a structured format (JSON), making them easy to query and analyze.
  • Multiple Sinks:
    • Console Sink: For easy viewing during development.
    • File Sink: For persistent log storage, with automatic rolling by file size.
  • Asynchronous Logging: All sinks are wrapped in Serilog.Sinks.Async to minimize the performance impact of logging on your application's request thread.
  • Rich Enrichment:
    • FromLogContext: Adds contextual information to logs.
    • WithExceptionDetails: Destructures exceptions to include detailed information like the stack trace.
    • WithSensitiveDataMasking: Automatically finds and masks sensitive data in log messages based on property names (e.g., "Password", "CreditCard").
  • Configuration-Driven: Reads settings from appsettings.json, allowing you to easily adjust log levels and other parameters without changing code.

🛠️ Installation

You can install the package via the .NET CLI:

dotnet add package RA.Utilities.Logging.Core

Or through the NuGet Package Manager in Visual Studio.


How to Use

Integrating the logger into your ASP.NET Core application is a two-step process.

Step 1: Configure appsettings.json

Add a Serilog section to your appsettings.json file. The AddRaSerilog method will automatically read from this section. You can override log levels for different sources as needed.

{
  "Serilog": {
    "MinimumLevel": {
      "Default": "Information",
      "Override": {
        "Microsoft": "Warning",
        "Microsoft.Hosting.Lifetime": "Information"
      }
    }
  },
  "AllowedHosts": "*"
}

Step 2: Add the Logger in Program.cs

Call the AddRaSerilog() extension method on your WebApplicationBuilder. This should be one of the first things you do to ensure all application startup events are logged.

using RA.Utilities.Logging.Core.Extensions; // Add this using statement

var builder = WebApplication.CreateBuilder(args);

// Add the RA Serilog configuration
builder.AddRaSerilog();

try
{
    // Add other services
    builder.Services.AddControllers();

    var app = builder.Build();

    // Your middleware pipeline
    app.UseHttpsRedirection();
    app.MapControllers();

    Log.Information("Starting application...");
    app.Run();
}
catch (Exception ex)
{
    // Log fatal exceptions that prevent the app from starting
    Log.Fatal(ex, "Application failed to start.");
}
finally
{
    // Ensure all buffered logs are written to sinks before the app closes
    Log.CloseAndFlush();
}

That's it! Your application is now configured with structured, asynchronous, and enriched logging. You can inject ILogger<T> anywhere in your application via dependency injection to write logs.


Contributing

Contributions are welcome! If you have a suggestion or find a bug, please open an issue to discuss it. Please follow the contribution guidelines outlined in the other RA.Utilities packages.

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

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
10.0.0-rc.2 134 10/30/2025