Skip to main content

Logging



Packages RA.Utilities.Logging.Core and RA.Utilities.Logging.Shared packages. They work together to provide a comprehensive and standardized logging solution for your applications.

RA.Utilities.Logging.Shared

The purpose of this package is to be a foundational library that provides common, shared data models for logging HTTP interactions.

  • Core Function: It defines the "shape" of your log data. It contains the C# classes (BaseHttpLogTemplate, HttpRequestLogTemplate, HttpResponseLogTemplate) that represent the structure of an HTTP request and response log entry.
  • Ensures Consistency: By providing these common models, it guarantees that any part of your ecosystem that logs an HTTP request (like a middleware or a delegating handler) will do so in a consistent, structured format.
  • Not for Direct Use: You typically wouldn't install or use this package directly in your application. Instead, it's a dependency that other RA.Utilities packages (like RA.Utilities.Api.Middlewares or RA.Utilities.Integrations) rely on.

In short, RA.Utilities.Logging.Shared is the blueprint for what your HTTP logs should look like.

RA.Utilities.Logging.Core

The purpose of this package is to provide a one-line setup for production-ready structured logging using Serilog.

  • Core Function: This is the package that contains the actual logging implementation and configuration logic. It takes the data models from RA.Utilities.Logging.Shared and uses a logging provider (like Serilog) to write them to a destination (like the console, a file, or a log management system).
  • Simplifies Setup: It's designed to be the main entry point for developers to configure logging. It likely contains extension methods that you would call in your Program.cs to get a complete logging setup with minimal effort.
  • Opinionated Configuration: It provides a pre-configured, "batteries-included" logging setup that follows best practices for structured logging in a web API environment.

In short, RA.Utilities.Logging.Core is the engine that does the logging, making it easy to get a powerful logging system up and running quickly.

⚙️ How They Work Together

  1. RA.Utilities.Logging.Shared defines the HttpRequestLogTemplate class.
  2. A component like the RequestResponseLoggingHandler from RA.Utilities.Integrations populates an instance of HttpRequestLogTemplate with data from an outgoing HttpClient request.
  3. The handler then passes this structured object to a logger. The logger, configured by RA.Utilities.Logging.Core, takes the object and uses Serilog to serialize it into a structured format (like JSON) and write it to the configured log output.

This separation of concerns is excellent, as it decouples the shape of the log data from the implementation of the logger itself.