Core Reference
Kanject.Core.Logs
Structured logging with correlation IDs, request scoping, and JSON output tuned for CloudWatch Logs Insights. Replaces Microsoft.Extensions.Logging providers — same ILogger<T> API, different sink.
Install
dotnet add package Kanject.Core.Logs Register
using Kanject.Core.Logs.Extensions;
builder.AddKanjectLogs(options =>
{
options.MinimumLevel = LogLevel.Information;
options.IncludeScopes = true;
}); Use it
public class CheckoutService(ILogger<CheckoutService> log)
{
public async Task<Receipt> CheckoutAsync(CheckoutRequest req)
{
// Per-call scope shows up on every nested log line
using var _ = log.BeginScope(new
{
UserId = req.UserId,
OrderId = req.OrderId,
});
log.LogInformation("Checkout started for {Currency} {Amount}", req.Currency, req.Amount);
// …
log.LogInformation("Checkout completed");
return new Receipt(/* ... */);
}
} CloudWatch output
{
"timestamp": "2026-05-04T14:22:11.193Z",
"level": "Information",
"category": "Acme.Analytics.Checkout.CheckoutService",
"message": "Checkout completed",
"scope": { "userId": "usr_abc", "orderId": "ord_9xk2" },
"traceId": "req_01HSXG2...",
"correlationId": "corr_01HSXG2..."
} traceId is the API Gateway request ID; correlationId flows across queue handlers and event subscribers so you can grep one ID across an entire transaction.
What ships with it
- Newline-delimited JSON output ready for CloudWatch Logs Insights queries
- Automatic
traceId+correlationIdon every line - Scope properties promoted to top-level fields
- PII-safe by default —
[Sensitive]-tagged fields redacted before write - Same
ILogger<T>API as the rest of .NET — no migration cost