RA.Utilities.Logging.Core
10.0.0-rc.2
Prefix Reserved
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
<PackageReference Include="RA.Utilities.Logging.Core" Version="10.0.0-rc.2" />
<PackageVersion Include="RA.Utilities.Logging.Core" Version="10.0.0-rc.2" />
<PackageReference Include="RA.Utilities.Logging.Core" />
paket add RA.Utilities.Logging.Core --version 10.0.0-rc.2
#r "nuget: RA.Utilities.Logging.Core, 10.0.0-rc.2"
#:package RA.Utilities.Logging.Core@10.0.0-rc.2
#addin nuget:?package=RA.Utilities.Logging.Core&version=10.0.0-rc.2&prerelease
#tool nuget:?package=RA.Utilities.Logging.Core&version=10.0.0-rc.2&prerelease
<p align="center"> <img src="../../Assets/Images/logging.svg" alt="RA.Utilities.Logging.Core Logo" width="128"> </p>
RA.Utilities.Logging.Core
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.Asyncto 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 | Versions 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. |
-
net10.0
- Destructurama.SystemTextJson (>= 0.1.0)
- Serilog.AspNetCore (>= 9.0.0)
- Serilog.Enrichers.Sensitive (>= 2.0.0)
- Serilog.Exceptions (>= 8.4.0)
- Serilog.Settings.AppSettings (>= 3.0.0)
- Serilog.Sinks.Async (>= 2.1.0)
- Serilog.Sinks.Console (>= 6.0.0)
- Serilog.Sinks.File (>= 7.0.0)
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 |