66using Microsoft . eShopOnContainers . BuildingBlocks . IntegrationEventLogEF . Services ;
77using Microsoft . eShopOnContainers . BuildingBlocks . IntegrationEventLogEF . Utilities ;
88using Microsoft . eShopOnContainers . Services . Ordering . Infrastructure ;
9+ using Microsoft . Extensions . Logging ;
910using System ;
1011using System . Data . Common ;
1112using System . Diagnostics ;
@@ -21,24 +22,30 @@ public class OrderingIntegrationEventService : IOrderingIntegrationEventService
2122 private readonly OrderingContext _orderingContext ;
2223 private readonly IntegrationEventLogContext _eventLogContext ;
2324 private readonly IIntegrationEventLogService _eventLogService ;
25+ private readonly ILogger < OrderingIntegrationEventService > _logger ;
2426
2527 public OrderingIntegrationEventService ( IEventBus eventBus ,
2628 OrderingContext orderingContext ,
2729 IntegrationEventLogContext eventLogContext ,
28- Func < DbConnection , IIntegrationEventLogService > integrationEventLogServiceFactory )
30+ Func < DbConnection , IIntegrationEventLogService > integrationEventLogServiceFactory ,
31+ ILogger < OrderingIntegrationEventService > logger )
2932 {
3033 _orderingContext = orderingContext ?? throw new ArgumentNullException ( nameof ( orderingContext ) ) ;
3134 _eventLogContext = eventLogContext ?? throw new ArgumentNullException ( nameof ( eventLogContext ) ) ;
3235 _integrationEventLogServiceFactory = integrationEventLogServiceFactory ?? throw new ArgumentNullException ( nameof ( integrationEventLogServiceFactory ) ) ;
3336 _eventBus = eventBus ?? throw new ArgumentNullException ( nameof ( eventBus ) ) ;
3437 _eventLogService = _integrationEventLogServiceFactory ( _orderingContext . Database . GetDbConnection ( ) ) ;
38+ _logger = logger ?? throw new ArgumentNullException ( nameof ( logger ) ) ;
3539 }
3640
3741 public async Task PublishEventsThroughEventBusAsync ( )
3842 {
3943 var pendindLogEvents = await _eventLogService . RetrieveEventLogsPendingToPublishAsync ( ) ;
44+
4045 foreach ( var logEvt in pendindLogEvents )
4146 {
47+ _logger . LogInformation ( "----- Publishing integration event {IntegrationEventId} ({@IntegrationEvent})" , logEvt . EventId , logEvt ) ;
48+
4249 try
4350 {
4451 await _eventLogService . MarkEventAsInProgressAsync ( logEvt . EventId ) ;
@@ -54,6 +61,8 @@ public async Task PublishEventsThroughEventBusAsync()
5461
5562 public async Task AddAndSaveEventAsync ( IntegrationEvent evt )
5663 {
64+ _logger . LogInformation ( "----- Saving integration event {IntegrationEventId} to repository ({@IntegrationEvent})" , evt . Id , evt ) ;
65+
5766 await _eventLogService . SaveEventAsync ( evt , _orderingContext . GetCurrentTransaction . GetDbTransaction ( ) ) ;
5867 }
5968 }
0 commit comments