Files
monorepo/LCU.API.Internal.MaidBotApi/LCU.Api.Internal.MaidBotApi/Consumers/LoggingEventConsumer.cs
T
2026-03-11 13:21:47 -05:00

40 lines
1.4 KiB
C#

using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using MassTransit;
using Serilog;
using LCU.Library.Internal.Exceptions;
using LCU.Api.Internal.MaidBotLib.Models;
using LCU.Api.Internal.MaidBotApi.Services;
namespace LCU.Api.Internal.MaidBotApi.Consumers;
public class LoggingEventConsumer : IConsumer<EventLog>
{
private readonly IServiceScopeFactory _scopeFactory;
public LoggingEventConsumer(IServiceScopeFactory scopeFactory)
{
_scopeFactory = scopeFactory;
}
public async Task Consume(ConsumeContext<EventLog> context)
{
try
{
using var scope = _scopeFactory.CreateScope();
await Task.Run(async () => await scope.ServiceProvider.GetRequiredService<IEventLogService>().HandleIncomingEventLog(context.Message));
}
catch (ServiceException serviceException)
{
Log.Fatal(serviceException, $"Handle Incoming EventLog Failure. " +
$"The Handle Incoming EventLog is placed on LCU.MaidBot_error.");
throw;
}
catch (Exception exception)
{
Log.Fatal(exception, $"Unexpected Handle Incoming EventLog Failure. " +
$"The Handle Incoming EventLog is placed on LCU.MaidBot_error.");
throw;
}
}
}