Files
Moonlight/Moonlight/App/Services/LogServices/AuditLogService.cs
Marcel Baumgartner d7b10aa224 Added logs
2023-03-05 01:49:04 +01:00

50 lines
1.3 KiB
C#

using Moonlight.App.Database.Entities.LogsEntries;
using Moonlight.App.Models.Misc;
using Moonlight.App.Repositories.LogEntries;
using Moonlight.App.Services.Sessions;
using Newtonsoft.Json;
namespace Moonlight.App.Services.LogServices;
public class AuditLogService
{
private readonly AuditLogEntryRepository Repository;
private readonly IdentityService IdentityService;
public AuditLogService(AuditLogEntryRepository repository, IdentityService identityService)
{
Repository = repository;
IdentityService = identityService;
}
public Task Log(AuditLogType type, object? data = null)
{
var ip = IdentityService.GetIp();
var entry = new AuditLogEntry()
{
Ip = ip,
Type = type,
System = false,
JsonData = data == null ? "" : JsonConvert.SerializeObject(data)
};
Repository.Add(entry);
return Task.CompletedTask;
}
public Task LogSystem(AuditLogType type, object? data = null)
{
var entry = new AuditLogEntry()
{
Type = type,
System = true,
JsonData = data == null ? "" : JsonConvert.SerializeObject(data)
};
Repository.Add(entry);
return Task.CompletedTask;
}
}