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 { private readonly IServiceScopeFactory _scopeFactory; public LoggingEventConsumer(IServiceScopeFactory scopeFactory) { _scopeFactory = scopeFactory; } public async Task Consume(ConsumeContext context) { try { using var scope = _scopeFactory.CreateScope(); await Task.Run(async () => await scope.ServiceProvider.GetRequiredService().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; } } }