public Task Audit(AuditItem auditItem, CancellationToken cancellationToken) { Debug.Assert(auditItem.ExecutedSuccessfully.HasValue); Debug.Assert(auditItem.ExecutionTimeMs.HasValue); if (auditItem.ExecutedSuccessfully.Value) { if (auditItem.AdditionalProperties.ContainsKey("UserId")) { _logger.LogInformation("Successfully executed command {commandType} for user {userId}", auditItem.CommandType, auditItem.AdditionalProperties["UserId"]); } else { _logger.LogInformation("Executing command {commandType}", auditItem.CommandType); } _metricCollector.Record(auditItem.CommandType, auditItem.ExecutionTimeMs.Value); } else { if (auditItem.AdditionalProperties.ContainsKey("UserId")) { _logger.LogInformation("Error executing command {commandType} for user {userId}", auditItem.CommandType, auditItem.AdditionalProperties["UserId"]); } else { _logger.LogInformation("Error executing command {commandType}", auditItem.CommandType); } _metricCollector.RecordWithError(auditItem.CommandType, auditItem.ExecutionTimeMs.Value); } return(Task.FromResult(0)); }