RA.Utilities.Logging.Core.Extensions
Namespace: RA.Utilities.Logging.Core.Extensions
The classes in this namespace are the configuration and setup entry points of the logging framework.
Each class extends exactly one type, and every member is declared as a C# 14 extension member (extension(Target) { ... }).
Classes
1. WebApplicationBuilderExtensions
This is the most important class in the namespace. Its purpose is to provide a "one-liner" setup for a production-ready Serilog configuration in a .NET application.
-
AddLoggingWithConfiguration(): The main entry point. It abstracts away the boilerplate needed to configure Serilog correctly. In a single call it:- Hooks Serilog into the host (
builder.Host.UseSerilog(...)). - Reads configuration from
appsettings.json(ReadFrom.Configuration). - Adds
WithExceptionDetailsto log detailed exception information. - Enables destructuring of
System.Text.Jsonobjects for better structured logs.
Request ID enrichment remains opt-in. Activate
WithRequestIdEnricherthrough theSerilog→Enrichconfiguration or by calling the fluent extension manually, then registerIHttpContextAccessorwithbuilder.Services.AddHttpContextAccessor(). - Hooks Serilog into the host (
2. LoggerEnrichmentConfigurationExtensions
Extends Serilog.Configuration.LoggerEnrichmentConfiguration.
WithRequestIdEnricher(): A fluent helper that adds the customRequestIdEnricherto the Serilog pipeline, contributing theTraceIdcorrelation property. It returns theLoggerConfigurationso it can be chained, and throwsArgumentNullExceptionwhen the receiver isnull.
3. ActivityExtensions
Extends System.Diagnostics.Activity.
GetActivityId(): Returns the activity's id as a string based on itsIdFormat(Hierarchical→Activity.Id,W3C→SpanId.ToHexString()). Returnsnullwhen there is no trace context, so downstream code can decide whether to add a trace property. This is the fallbackRequestIdEnricheruses when noHttpContextis available.
AddLoggingWithConfiguration() and WithRequestIdEnricher() were previously declared together in a single LoggingExtensions class. Since v10.1.1 the methods live in one class per extended type (WebApplicationBuilderExtensions and LoggerEnrichmentConfigurationExtensions), and ActivityExtensions was converted to a C# 14 extension member. Method names, signatures, and the namespace are unchanged for call sites — see the migration guide for the rare cases that need updating.
🧠 Summary
In summary, the RA.Utilities.Logging.Core.Extensions namespace is the "developer-friendly API" for the logging library.
It makes it simple to get a powerful, pre-configured, and consistent logging implementation up and running with minimal effort, while keeping each extension class focused on the type it extends.
ActivityExtensions
The ActivityExtensions class provides a trace-identifier helper for System.Diagnostics.Activity.
LoggerEnrichmentConfigurationExtensions
The LoggerEnrichmentConfigurationExtensions class provides the fluent entry point for adding the RequestIdEnricher to a Serilog pipeline.
WebApplicationBuilderExtensions
The WebApplicationBuilderExtensions class is the primary entry point for wiring Serilog into an ASP.NET Core application.