namespace JSMR.Application.Logging; public sealed class LogObjectBuilder { private readonly Dictionary _d = []; public LogObjectBuilder Add(string key, object? value) { if (value is null) return this; _d[key] = value; return this; } public LogObjectBuilder AddIfNotEmpty(string key, string? value) => string.IsNullOrWhiteSpace(value) ? this : Add(key, value); public LogObjectBuilder AddIfNotEmpty(string key, IReadOnlyCollection? value, int? preview = null) { if (value is null || value.Count == 0) return this; if (preview is null || value.Count <= preview) return Add(key, value); // Store small preview + count so logs stay compact return Add(key, new { Preview = value.Take(preview.Value), value.Count }); } public LogObjectBuilder AddIfNotDefault(string key, T value) where T : struct, IEquatable => value.Equals(default) ? this : Add(key, value); public object Build() => _d; }