forked from kabdelrazek-do/SecurityAndAuthentication
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuditLogger.cs
More file actions
40 lines (37 loc) · 1.27 KB
/
AuditLogger.cs
File metadata and controls
40 lines (37 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Threading.Tasks;
using SafeVault.Data;
namespace SafeVault.Services
{
/// <summary>
/// Audit logging service for security events
/// </summary>
public class AuditLogger
{
private readonly SecureDatabaseManager _dbManager;
public AuditLogger(SecureDatabaseManager dbManager)
{
_dbManager = dbManager ?? throw new ArgumentNullException(nameof(dbManager));
}
/// <summary>
/// Logs an audit event
/// </summary>
/// <param name="userId">User ID (nullable)</param>
/// <param name="action">Action performed</param>
/// <param name="details">Action details</param>
/// <param name="ipAddress">Client IP address</param>
/// <param name="userAgent">Client user agent</param>
public async Task LogAsync(int? userId, string action, string details, string ipAddress, string userAgent)
{
try
{
await _dbManager.LogAuditEventAsync(userId, action, details, ipAddress, userAgent);
}
catch
{
// Log error but don't throw to avoid breaking the main operation
// In production, use proper logging framework
}
}
}
}