RA.Utilities.Logging.Core.Extensions
Namespace: RA.Utilities.Logging.Core.Extensions
The classes in this namespace serve as the primary configuration and setup entry points for your logging framework. They provide convenient, fluent extension methods that simplify the process of integrating and enriching your Serilog-based logger.
Let's break down each class:
1. LoggingExtensions
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(this WebApplicationBuilder builder): This is the main entry point. It abstracts away all the complex boilerplate needed to configure Serilog correctly. In a single call, it:- Hooks Serilog into the host.
- Reads configuration from
appsettings.json. - Adds the custom
RequestIdEnricherfor request correlation. - Adds the
WithExceptionDetailsenricher to log detailed exception information. - Enables destructuring of
System.Text.Jsonobjects for better structured logs. - Ensures the necessary [
IHttpContextAccessor](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.ihttpcontextaccessor) is registered in the DI container. - WithRequestIdEnricher(this
LoggerEnrichmentConfigurationenrich): This is a small helper that creates a clean, fluent syntax for adding your custom RequestIdEnricher to the Serilog pipeline, improving readability in the main setup method.
🧠 Summary
In summary, the RA.Utilities.Logging.Core.Extensions namespace is the "developer-friendly API" for your logging library.
It makes it incredibly simple for a developer to get a powerful, pre-configured,
and consistent logging implementation up and running with minimal effort.
📄️ LoggingExtensions
The LoggingExtensions class is the primary entry point for your logging framework.