Class AdminAuditService
Append-only operator audit log.
public sealed class AdminAuditService : BaseService<AdminAuditEntity>, IAdminAuditService
- Inheritance
-
AdminAuditService
- Implements
- Inherited Members
Remarks
EF throughout and no raw SQL, for the same reason as WebSessionService: an
unqualified raw statement resolves against the connection's search_path rather than
the model's configured schema, and on a deployment where those differ it silently affects
nothing. A log that silently writes nothing is worse than no log, because it is believed.
Constructors
AdminAuditService(INpgsqlDbContextFactory)
public AdminAuditService(INpgsqlDbContextFactory dbContextFactory)
Parameters
dbContextFactoryINpgsqlDbContextFactory
Methods
AppendAsync(AdminAuditData, CancellationToken)
Records one action.
public Task<DatabaseResult<long>> AppendAsync(AdminAuditData entry, CancellationToken cancellationToken = default)
Parameters
entryAdminAuditDataThe action.
OccurredUtcis filled in when left at default.cancellationTokenCancellationTokenCancellation token.
Returns
Remarks
Call this for refusals as well as successes. A log holding only what worked cannot distinguish an operator who never tried from one who tried and was stopped, and the second is the one worth knowing about.
Returns the new row's id. Callers that cannot usefully react to a failure should still check the result and log it: a write that silently did not happen is the one failure mode that makes the whole table untrustworthy.
FetchActionsAsync(CancellationToken)
The distinct action identifiers present in the log, for populating a filter.
public Task<DatabaseResult<IReadOnlyList<string>>> FetchActionsAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenCancellation token.
Returns
Remarks
Read from the data rather than from a constant list, so an action added by a future command appears in the filter without anybody remembering to register it.
SearchAsync(AdminAuditQuery, CancellationToken)
Reads a page of the log, newest first.
public Task<DatabaseResult<AdminAuditPage>> SearchAsync(AdminAuditQuery query, CancellationToken cancellationToken = default)
Parameters
queryAdminAuditQueryFilters. Every field is optional.
cancellationTokenCancellationTokenCancellation token.