.NET by Patrik

Logging Complex Data in a Readable Way

Complex objects and dictionaries often contain far more data than a log entry really needs. Logging them directly can flood the log with noise or produce unreadable output.

A better approach is to extract only the most relevant values and create a compact summary:

var summary = dataMap.Select(x => new
{
    Key = x.Key,
    Count = x.Value.Count,
    Status = x.Value.Status
});

logger.LogInformation("DataSummary={Summary}", summary);

This keeps the log focused on what matters: identifiers, counts, and simple status values. The result is easier to scan, easier to search, and more useful during debugging or monitoring.

logging
readability
data
structure
diagnostics

Comments