Files
HTCloud/HT.Cloud.Service/Event/LogEventSubscriber.cs

39 lines
1.1 KiB
C#
Raw Normal View History

2023-03-03 16:07:50 +08:00
using Jaina;
using Microsoft.Extensions.DependencyInjection;
2024-11-14 09:01:37 +08:00
using SqlSugar;
2023-03-03 16:07:50 +08:00
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;
2024-11-14 09:01:37 +08:00
using var dbContext = new SqlSugarClient(DBInitialize.GetConnectionConfigs(true),
//全局上下文生效
db =>
{
foreach (var item in DBInitialize.GetConnectionConfigs(false))
{
2024-11-14 09:01:55 +08:00
db.GetConnection(item.ConfigId).DefaultConfig();
2024-11-14 09:01:37 +08:00
}
});
await new LogService(dbContext).WriteDbLog(input, user);
await Task.CompletedTask;
}
2023-03-03 16:07:50 +08:00
}
}