Skip to content

Commit

Permalink
Update ChangeCollector.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
pwelter34 committed Aug 23, 2024
1 parent 7b9b544 commit c8830ab
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/MediatR.CommandQuery.Audit/ChangeCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ public IReadOnlyList<AuditRecord<TKey>> CollectGroupChanges<TProperty>(IEnumerab

foreach (var group in entities.GroupBy(groupSelector))
{
var key = group.Key?.ToString();

try
{
LogCollectingChanges(_logger, entityName, group.Key);
LogCollectingChanges(_logger, entityName, key);

var groupList = group
.OrderBy(p => p.PeriodEnd)
Expand All @@ -83,7 +85,7 @@ public IReadOnlyList<AuditRecord<TKey>> CollectGroupChanges<TProperty>(IEnumerab
}
catch (Exception ex)
{
LogCollectingError(_logger, entityName, group.Key, ex.Message, ex);
LogCollectingError(_logger, entityName, key, ex.Message, ex);

throw;
}
Expand Down Expand Up @@ -178,9 +180,9 @@ public IEnumerable<AuditRecord<TKey>> CollectChanges(IEnumerable<TEntity> entiti


[LoggerMessage(1, LogLevel.Debug, "Collecting changes for {EntityName} with key {EntityKey} ...")]
static partial void LogCollectingChanges(ILogger logger, string entityName, object entityKey);
static partial void LogCollectingChanges(ILogger logger, string entityName, string? entityKey);

[LoggerMessage(2, LogLevel.Error, "Error collecting changes for {EntityName} with key {EntityKey}: {ErrorMessage}")]
static partial void LogCollectingError(ILogger logger, string entityName, object entityKey, string errorMessage, Exception? exception);
static partial void LogCollectingError(ILogger logger, string entityName, string? entityKey, string errorMessage, Exception? exception);

}

0 comments on commit c8830ab

Please sign in to comment.