22using System . Threading . Tasks ;
33using MediatR ;
44using Microsoft . AspNetCore . SignalR ;
5+ using Microsoft . Extensions . Logging ;
56using NetCoreKit . Infrastructure . Bus . Kafka ;
67using Project . Proto ;
78
@@ -16,29 +17,43 @@ public class ProjectHostService : HostedService,
1617 INotificationHandler < Notifications . TaskCreated >
1718 {
1819 private readonly IDispatchedEventBus _eventBus ;
20+ private readonly ILogger < ProjectHostService > _logger ;
1921
20- public ProjectHostService ( IHubContext < ProjectHub > context , IDispatchedEventBus eventBus )
22+ public ProjectHostService ( IHubContext < ProjectHub > context , IDispatchedEventBus eventBus , ILoggerFactory loggerFactory )
2123 {
2224 _eventBus = eventBus ;
2325 Clients = context . Clients ;
26+ _logger = loggerFactory . CreateLogger < ProjectHostService > ( ) ;
2427 }
2528
2629 private IHubClients Clients { get ; }
2730
2831 public async Task Handle ( Notifications . ProjectCreated notification , CancellationToken cancellationToken )
2932 {
33+ _logger . LogInformation ( "Pushing message to projectCreatedNotify..." ) ;
3034 await Clients . All . SendAsync ( "projectCreatedNotify" , notification , cancellationToken ) ;
3135 }
3236
3337 public async Task Handle ( Notifications . TaskCreated notification , CancellationToken cancellationToken )
3438 {
39+ _logger . LogInformation ( "Pushing message to taskAddedToProjectNotify..." ) ;
3540 await Clients . All . SendAsync ( "taskAddedToProjectNotify" , notification , cancellationToken ) ;
3641 }
3742
3843 protected override Task ExecuteAsync ( CancellationToken cancellationToken )
3944 {
40- Task . Run ( ( ) => _eventBus . Subscribe < ProjectCreatedMsg > ( "project-created" ) , cancellationToken ) ;
41- Task . Run ( ( ) => _eventBus . Subscribe < TaskCreatedMsg > ( "task-created" ) , cancellationToken ) ;
45+ Task . Run ( ( ) =>
46+ {
47+ _logger . LogInformation ( "[NCK] Start to subscribe to project-created..." ) ;
48+ return _eventBus . Subscribe < ProjectCreatedMsg > ( "project-created" ) ;
49+ } , cancellationToken ) ;
50+
51+ Task . Run ( ( ) =>
52+ {
53+ _logger . LogInformation ( "[NCK] Start to subscribe to task-created..." ) ;
54+ return _eventBus . Subscribe < TaskCreatedMsg > ( "task-created" ) ;
55+ } , cancellationToken ) ;
56+
4257 return Task . CompletedTask ;
4358 }
4459 }
0 commit comments