namespace Admin.NET.Core; /// /// 日志事件订阅 /// public class LogEventSubscriber : IEventSubscriber { private readonly IServiceProvider _serviceProvider; public LogEventSubscriber(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; } /// /// 增加操作日志 /// /// /// [EventSubscribe("Add:OpLog")] public async Task CreateOpLog(EventHandlerExecutingContext context) { using var scope = _serviceProvider.CreateScope(); var _rep = scope.ServiceProvider.GetRequiredService>(); await _rep.InsertAsync((SysLogOp)context.Source.Payload); } /// /// 增加异常日志 /// /// /// [EventSubscribe("Add:ExLog")] public async Task CreateExLog(EventHandlerExecutingContext context) { using var scope = _serviceProvider.CreateScope(); var _rep = scope.ServiceProvider.GetRequiredService>(); await _rep.InsertAsync((SysLogEx)context.Source.Payload); // 发送邮件 await scope.ServiceProvider.GetRequiredService().SendEmail(JSON.Serialize(context.Source.Payload)); } /// /// 增加访问日志 /// /// /// [EventSubscribe("Add:VisLog")] public async Task CreateVisLog(EventHandlerExecutingContext context) { using var scope = _serviceProvider.CreateScope(); var _rep = scope.ServiceProvider.GetRequiredService>(); await _rep.InsertAsync((SysLogVis)context.Source.Payload); } }