39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
using Jaina;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using SqlSugar;
|
|
using System.Threading.Tasks;
|
|
using HT.Cloud.Code;
|
|
using HT.Cloud.Domain.SystemSecurity;
|
|
using HT.Cloud.Service.SystemSecurity;
|
|
|
|
namespace HT.Cloud.Service.Event
|
|
{
|
|
// 实现 IEventSubscriber 接口
|
|
public class LogEventSubscriber : IEventSubscriber
|
|
{
|
|
|
|
public LogEventSubscriber()
|
|
{
|
|
}
|
|
|
|
[EventSubscribe("Log:create")]
|
|
public async Task SendMessages(EventHandlerExecutingContext context)
|
|
{
|
|
var todo = (BaseEventSource)context.Source;
|
|
var input = (LogEntity)todo.Payload;
|
|
var user = todo.User;
|
|
using var dbContext = new SqlSugarClient(DBInitialize.GetConnectionConfigs(true),
|
|
//全局上下文生效
|
|
db =>
|
|
{
|
|
foreach (var item in DBInitialize.GetConnectionConfigs(false))
|
|
{
|
|
db.GetConnection(item.ConfigId).DefaultConfig();
|
|
}
|
|
});
|
|
await new LogService(dbContext).WriteDbLog(input, user);
|
|
await Task.CompletedTask;
|
|
}
|
|
}
|
|
}
|