Kanject.Core.Logs

View .md

A queryable, DynamoDB-backed log store — not a Microsoft.Extensions.Logging sink. Write records into named log groups with ILogManager.LogAsync, and read them back — filtered by text and time window — with GetLogsAsync. Use it for durable, application-level audit and event trails your service can query itself, alongside (not instead of) your normal ILogger.

Install

bash
dotnet add package Kanject.Core.Logs.Provider.DynamoDb

The DynamoDB provider implements ILogManager from Kanject.Core.Logs.Abstractions (pulled in transitively).

Register

csharp
using Kanject.Core.Logs.Provider.DynamoDb.Extensions;builder.Services.AddLogStore(options =>{    options.Ttl       = 30;                  // retention, in days    options.Namespace = appSettings.Stage;   // per-stage log-table isolation    options.AwsRegion = appSettings.AwsRegion;});

AddLogStore wires the log DbContext and ILogManager. Ttl sets record retention in days; Namespace isolates the store per stage (it inherits the DynamoDB config surface — region, credentials, table).

Write a record

csharp
public class AuditService(ILogManager logs){    // Persist a log record under a named group.    public Task RecordAsync(string customerId, string action)        => logs.LogAsync(new LogRequest        {            LogGroup = "customer-actions",            Log      = $"{customerId} {action}",        });}

Read them back

Query a group by text and time range — the read is paginated and returns records plus page metadata:

csharp
// Query a group back, filtered by text and time window (paginated).var (entries, metadata) = await logs.GetLogsAsync(new GetSystemLogsRequest{    LogGroup  = "customer-actions",    Query     = "c-014",    StartDate = DateTime.UtcNow.AddDays(-7),    EndDate   = DateTime.UtcNow,});// each entry: Id (Guid), LogGroup, Log, CreatedOn

What ships with it

  • ILogManager.LogAsync(LogRequest { LogGroup, Log }) — persist a record into a named group
  • ILogManager.GetLogsAsync(GetSystemLogsRequest { Id, LogGroup, Query, StartDate, EndDate }) — paginated query
  • Each record is { Guid Id, string LogGroup, string Log, DateTime CreatedOn }
  • DynamoDB-backed with a configurable Ttl (days) for automatic expiry
  • Namespace prefixing for per-stage / per-tenant isolation
Was this page helpful?