LogEventSubscriber.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using Furion.DatabaseAccessor;
  2. using Furion.EventBus;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using System;
  5. using System.Threading.Tasks;
  6. namespace YBEE.EQM.Core
  7. {
  8. public class LogEventSubscriber : IEventSubscriber
  9. {
  10. public IServiceProvider Services { get; }
  11. public LogEventSubscriber(IServiceProvider services)
  12. {
  13. Services = services;
  14. }
  15. [EventSubscribe("Create:OpLog")]
  16. public async Task CreateOpLog(EventHandlerExecutingContext context)
  17. {
  18. using var scope = Services.CreateScope();
  19. var _repository = scope.ServiceProvider.GetRequiredService<IRepository<SysLogOp>>();
  20. var log = (SysLogOp)context.Source.Payload;
  21. await _repository.InsertNowAsync(log);
  22. }
  23. [EventSubscribe("Create:ExLog")]
  24. public async Task CreateExLog(EventHandlerExecutingContext context)
  25. {
  26. using var scope = Services.CreateScope();
  27. var _repository = scope.ServiceProvider.GetRequiredService<IRepository<SysLogEx>>();
  28. var log = (SysLogEx)context.Source.Payload;
  29. await _repository.InsertNowAsync(log);
  30. }
  31. [EventSubscribe("Create:VisLog")]
  32. public async Task CreateVisLog(EventHandlerExecutingContext context)
  33. {
  34. using var scope = Services.CreateScope();
  35. var _repository = scope.ServiceProvider.GetRequiredService<IRepository<SysLogVis>>();
  36. var log = (SysLogVis)context.Source.Payload;
  37. await _repository.InsertNowAsync(log);
  38. }
  39. }
  40. }