diff --git a/src/Hosting/Queue/src/MessageContextScope.cs b/src/Hosting/Queue/src/MessageContextScope.cs new file mode 100644 index 0000000..509c59b --- /dev/null +++ b/src/Hosting/Queue/src/MessageContextScope.cs @@ -0,0 +1,28 @@ +namespace ClickView.GoodStuff.Hosting.Queue; + +using System.Collections; +using Queues.RabbitMq; + +internal class MessageContextScope(MessageContext context) : IReadOnlyList> +{ + public IEnumerator> GetEnumerator() + { + for (var i = 0; i < Count; ++i) + { + yield return this[i]; + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public int Count => 1; + + public KeyValuePair this[int index] => index switch + { + 0 => new KeyValuePair("MessageId", context.Id), + _ => throw new IndexOutOfRangeException(nameof(index)), + }; +} diff --git a/src/Hosting/Queue/src/QueueHostedService.cs b/src/Hosting/Queue/src/QueueHostedService.cs index 809c6be..4b1162a 100644 --- a/src/Hosting/Queue/src/QueueHostedService.cs +++ b/src/Hosting/Queue/src/QueueHostedService.cs @@ -47,6 +47,8 @@ protected override Task SubscribeAsync(IQueueClient queueCl /// private async Task OnMessageAsync(MessageContext messageContext, CancellationToken cancellationToken) { + using var logScope = Logger.BeginScope(new MessageContextScope(messageContext)); + Logger.QueueMessageReceived(messageContext.Id, messageContext.Timestamp); try