RA.Utilities.Logging.Core
10.1.2
Prefix Reserved
dotnet add package RA.Utilities.Logging.Core --version 10.1.2
NuGet\Install-Package RA.Utilities.Logging.Core -Version 10.1.2
<PackageReference Include="RA.Utilities.Logging.Core" Version="10.1.2" />
<PackageVersion Include="RA.Utilities.Logging.Core" Version="10.1.2" />
<PackageReference Include="RA.Utilities.Logging.Core" />
paket add RA.Utilities.Logging.Core --version 10.1.2
#r "nuget: RA.Utilities.Logging.Core, 10.1.2"
#:package RA.Utilities.Logging.Core@10.1.2
#addin nuget:?package=RA.Utilities.Logging.Core&version=10.1.2
#tool nuget:?package=RA.Utilities.Logging.Core&version=10.1.2
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. It ships with pre-wired Serilog packages (Console, File, Async sinks; Exception, Sensitive Data enrichers) so that consumers can configure them declaratively via appsettings.json without adding individual NuGet references.
📚 Table of Contents
- Purpose
- Key Features
- Installation
- How to Use
- Contributing
Purpose
Setting up a comprehensive logging solution from scratch can be repetitive. This package abstracts away the boilerplate Serilog wiring by providing a single extension method, AddLoggingWithConfiguration, that bootstraps a production-ready foundation.
Key Features
Configured automatically by AddLoggingWithConfiguration:
- Configuration-driven: Reads Serilog settings from
appsettings.jsonviaReadFrom.Configuration, so log levels, sinks, and enrichers are controlled declaratively. - Exception details: Uses
Serilog.Exceptionsto destructure exceptions with full stack trace detail. - System.Text.Json destructuring: Uses
Destructurama.SystemTextJsonso thatJsonElementand related types log as readable values instead ofValueKindenum names.
Optional — activate RequestIdEnricher yourself:
- Request ID enrichment: Adds
XRequestIdandTraceIdproperties from thex-request-idheader,HttpContext.TraceIdentifier, or the currentActivity. Add{ "Name": "WithRequestIdEnricher" }toSerilog→Enrich, or call.Enrich.WithRequestIdEnricher()manually, and registerIHttpContextAccessorwithbuilder.Services.AddHttpContextAccessor().
Available for appsettings.json configuration (packages are included as dependencies — no additional NuGet install needed):
- Console sink —
Serilog.Sinks.Console - File sink —
Serilog.Sinks.Filewith rolling and size limits - Async wrapper —
Serilog.Sinks.Asyncto offload I/O from the request thread - Sensitive data masking —
Serilog.Enrichers.Sensitive
🛠️ 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 AddLoggingWithConfiguration method reads from this section automatically.
{
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information",
"System": "Warning"
}
},
"Using": [
"Serilog.Sinks.Console",
"Serilog.Sinks.File",
"Serilog.Sinks.Async",
"Serilog.Enrichers.Sensitive",
"Serilog.Exceptions"
],
"Enrich": [
{ "Name": "WithExceptionDetails" },
{ "Name": "WithRequestIdEnricher" },
{
"Name": "WithSensitiveDataMasking",
"Args": {
"options": {
"MaskValue": "***SECRET***",
"Mode": "Globally"
}
}
}
],
"WriteTo:Async": {
"Name": "Async",
"Args": {
"configure": [
{
"Name": "File",
"Args": {
"path": "Logs/app-.log",
"rollingInterval": "Day",
"rollOnFileSizeLimit": true,
"outputTemplate": "{Timestamp:G} [{Level}] ({XRequestId})({TraceId}) {Message:lj} ({SourceContext}){NewLine}{Exception}"
}
},
{
"Name": "Console",
"Args": {
"outputTemplate": "{Timestamp:G} [{Level}] ({XRequestId})({TraceId}) {Message:lj} ({SourceContext}){NewLine}{Exception}"
}
}
]
}
}
}
}
Step 2: Add the Logger in Program.cs
Call AddLoggingWithConfiguration() 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);
// Required when WithRequestIdEnricher is enabled in appsettings.json
builder.Services.AddHttpContextAccessor();
// Configure Serilog with opinionated defaults
builder.AddLoggingWithConfiguration();
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 (>= 10.0.0)
- Serilog.Enrichers.Sensitive (>= 2.1.0)
- Serilog.Exceptions (>= 8.4.0)
- Serilog.Sinks.Async (>= 2.1.0)
- Serilog.Sinks.Console (>= 6.1.1)
- 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.1.2 | 125 | 10/19/2026 |
| 10.1.1 | 110 | 10/18/2026 |
| 10.1.0 | 116 | 9/28/2026 |
| 10.0.0 | 393 | 11/23/2025 |
| 10.0.0-rc.2 | 228 | 10/30/2025 |