/// <summary> /// Initializes a new instance of the <see cref="PostAuditActionRequest" /> class. /// </summary> /// <param name="AuditAction">The audit action (required).</param> public PostAuditActionRequest(AuditActionEnum AuditAction = default(AuditActionEnum)) { // to ensure "AuditAction" is required (not null) if (AuditAction == null) { throw new InvalidDataException("AuditAction is a required property for PostAuditActionRequest and cannot be null"); } else { this.AuditAction = AuditAction; } }
public async Task SaveAuditLog(string description, AuditActionEnum action) { var userId = _contextAccessor.HttpContext.GetUserId(); var auditLog = new AuditLog { Action = action.GetDisplayName(), Description = description, IpAddress = _contextAccessor.HttpContext.Connection.RemoteIpAddress.ToString(), Created = DateTime.Now, CreatedBy = userId }; await _repository.Create(auditLog); }
/// <summary> /// Add a log to the database /// </summary> /// <param name="detail">The detail of the action</param> /// <param name="actionEnum">The type of action</param> public AuditTrail Log(string detail, AuditActionEnum actionEnum) { try { var audit = new AuditTrail { Details = $"{detail}", TimeStamp = DateTime.Now, AuditAction = actionEnum }; var auditTrail = _auditTrailRepository.Add(audit); _log.Info("Audit trail created"); return auditTrail; } catch (Exception ex) { _log.Error("Others", ex); return null; } }