public async Task Log(string eventType, string details, string ipAddress) { var auditLogItem = new AuditLogItem { EventType = eventType, Details = details, IpAddress = ipAddress, Timestamp = DateTimeOffset.Now }; await _auditLogStorage.LogAsync(auditLogItem); }
internal async Task LogAsync(AuditLogItem auditLogItem) { using (var connection = new SqlConnection(_identityOptions.ConnectionString)) { using (var command = new SqlCommand(_insertSql, connection)) { command.Parameters.Add(new SqlParameter("@Details", auditLogItem.Details)); command.Parameters.Add(new SqlParameter("@EventType", auditLogItem.EventType)); command.Parameters.Add(new SqlParameter("@IpAddress", auditLogItem.IpAddress)); command.Parameters.Add(new SqlParameter("@Timestamp", auditLogItem.Timestamp)); await connection.OpenAsync(); auditLogItem.Id = (int)await command.ExecuteScalarAsync(); } } }