Added audit logging. Added admin view for audit log
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user