namespace MxGateway.Server.Diagnostics; public sealed record GatewayLogScope( string? SessionId = null, int? WorkerProcessId = null, ulong? CorrelationId = null, string? CommandMethod = null, string? ClientIdentity = null) { public IReadOnlyDictionary ToDictionary() { Dictionary values = []; AddIfPresent(values, "SessionId", SessionId); AddIfPresent(values, "WorkerProcessId", WorkerProcessId); AddIfPresent(values, "CorrelationId", CorrelationId); AddIfPresent(values, "CommandMethod", CommandMethod); AddIfPresent(values, "ClientIdentity", GatewayLogRedactor.RedactClientIdentity(ClientIdentity)); return values; } private static void AddIfPresent( Dictionary values, string key, object? value) { if (value is not null) { values[key] = value; } } }