payne
2024-04-24 0632e972f30627c5bd6c5a84373bab8e54a4c3ed
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
31
32
33
34
35
36
37
38
39
40
41
42
43
using Furion.DatabaseAccessor;
using Furion.EventBus;
using Microsoft.Extensions.DependencyInjection;
 
namespace Admin.NET.Core
{
    public class LogEventSubscriber : IEventSubscriber
    {
        public IServiceProvider Services { get; }
 
        public LogEventSubscriber(IServiceProvider services)
        {
            Services = services;
        }
 
        [EventSubscribe("Create:OpLog")]
        public async Task CreateOpLog(EventHandlerExecutingContext context)
        {
            using var scope = Services.CreateScope();
            var _repository = scope.ServiceProvider.GetRequiredService<IRepository<SysLogOp>>();
            var log = (SysLogOp)context.Source.Payload;
            await _repository.InsertNowAsync(log);
        }
 
        [EventSubscribe("Create:ExLog")]
        public async Task CreateExLog(EventHandlerExecutingContext context)
        {
            using var scope = Services.CreateScope();
            var _repository = scope.ServiceProvider.GetRequiredService<IRepository<SysLogEx>>();
            var log = (SysLogEx)context.Source.Payload;
            await _repository.InsertNowAsync(log);
        }
 
        [EventSubscribe("Create:VisLog")]
        public async Task CreateVisLog(EventHandlerExecutingContext context)
        {
            using var scope = Services.CreateScope();
            var _repository = scope.ServiceProvider.GetRequiredService<IRepository<SysLogVis>>();
            var log = (SysLogVis)context.Source.Payload;
            await _repository.InsertNowAsync(log);
        }
    }
}