Skip to main content

Logging.Extensions

NuGet Version NuGet Downloads

Microsoft.Extensions.Logging integration with automatic sensitive field redaction.

Installation

dotnet add package Oproto.FluentDynamoDb.Logging.Extensions

Key Features

  • Automatic Redaction - Redact sensitive fields in logs
  • Structured Logging - Rich structured log output
  • Performance Metrics - Log operation timing and statistics
  • Configurable - Control log levels and redaction rules

Quick Start

Configure logging at runtime using FluentDynamoDbOptions.WithLogger():

using Microsoft.Extensions.Logging;
using Oproto.FluentDynamoDb;
using Oproto.FluentDynamoDb.Logging.Extensions;

// Create logger factory
var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddConsole();
builder.SetMinimumLevel(LogLevel.Debug);
});

// Configure FluentDynamoDb with logging
var options = new FluentDynamoDbOptions()
.WithLogger(loggerFactory.ToDynamoDbLogger<ProductsTable>());

var table = new ProductsTable(client, "products", options);

// All operations are now logged
await table.Get<Product>().WithKey("pk", "product-123").ExecuteAsync();

Extension Methods

The package provides ToDynamoDbLogger() extension methods:

// From ILoggerFactory with type category
IDynamoDbLogger logger = loggerFactory.ToDynamoDbLogger<MyTable>();

// From ILoggerFactory with string category
IDynamoDbLogger logger = loggerFactory.ToDynamoDbLogger("MyCategory");

// From ILogger
ILogger msLogger = loggerFactory.CreateLogger<MyTable>();
IDynamoDbLogger logger = msLogger.ToDynamoDbLogger();

ASP.NET Core Integration

// Program.cs
builder.Services.AddSingleton<ProductsTable>(sp =>
{
var client = sp.GetRequiredService<IAmazonDynamoDB>();
var loggerFactory = sp.GetRequiredService<ILoggerFactory>();

var options = new FluentDynamoDbOptions()
.WithLogger(loggerFactory.ToDynamoDbLogger<ProductsTable>());

return new ProductsTable(client, "products", options);
});

NuGet

View on NuGet.org