Added audit logging. Added admin view for audit log

This commit is contained in:
Marcel Baumgartner
2023-03-06 02:21:23 +01:00
parent d7b10aa224
commit 62cd63f56b
39 changed files with 2754 additions and 153 deletions

View File

@@ -10,17 +10,17 @@ namespace Moonlight.App.Services.LogServices;
public class ErrorLogService
{
private readonly ErrorLogEntryRepository Repository;
private readonly IdentityService IdentityService;
private readonly IHttpContextAccessor HttpContextAccessor;
public ErrorLogService(ErrorLogEntryRepository repository, IdentityService identityService)
public ErrorLogService(ErrorLogEntryRepository repository, IHttpContextAccessor httpContextAccessor)
{
Repository = repository;
IdentityService = identityService;
HttpContextAccessor = httpContextAccessor;
}
public Task Log(Exception exception, params object[] objects)
{
var ip = IdentityService.GetIp();
var ip = GetIp();
var entry = new ErrorLogEntry()
{
@@ -74,4 +74,17 @@ public class ErrorLogService
return fullName;
}
private string GetIp()
{
if (HttpContextAccessor.HttpContext == null)
return "N/A";
if(HttpContextAccessor.HttpContext.Request.Headers.ContainsKey("X-Real-IP"))
{
return HttpContextAccessor.HttpContext.Request.Headers["X-Real-IP"]!;
}
return HttpContextAccessor.HttpContext.Connection.RemoteIpAddress!.ToString();
}
}