-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathEventLogger.cs
30 lines (25 loc) · 907 Bytes
/
EventLogger.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
namespace Scaffold.Application.Common.Instrumentation;
using System.Threading;
using System.Threading.Tasks;
using MediatR;
using Microsoft.Extensions.Logging;
using Scaffold.Application.Common.Messaging;
internal class EventLogger<TNotification> : EventLoggerBase, INotificationHandler<TNotification>
where TNotification : INotification
{
private readonly ILogger logger;
public EventLogger(ILogger<TNotification> logger)
{
this.logger = logger;
}
public Task Handle(TNotification notification, CancellationToken cancellationToken)
{
if (notification is IAuditableEvent auditableEvent)
{
LogAuditableEvent(this.logger, auditableEvent.Type, auditableEvent.Description);
return Task.CompletedTask;
}
LogNonAuditableEvent(this.logger, notification.GetType().FullName);
return Task.CompletedTask;
}
}