Class AuditService
Service for managing audit events.
Implements
Inherited Members
Namespace: DataWeb.Audit
Assembly: DataWeb.Core.dll
Syntax
public class AuditService : IAuditService
Remarks
This service handles the creation, retrieval, and deletion of audit events, providing automatic validation, sanitization, and enrichment of audit data.
Constructors
AuditService(IHttpService, IConfigurationService, IAuditEventStore, TimeProvider)
Service for managing audit events.
Declaration
public AuditService(IHttpService httpService, IConfigurationService configurationService, IAuditEventStore auditEventStore, TimeProvider timeProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| IHttpService | httpService | |
| IConfigurationService | configurationService | |
| IAuditEventStore | auditEventStore | |
| TimeProvider | timeProvider |
Remarks
This service handles the creation, retrieval, and deletion of audit events, providing automatic validation, sanitization, and enrichment of audit data.
Methods
DeleteExpiredEntriesAsync(DateTimeOffset, CancellationToken)
Asynchronously deletes audit events that have expired.
Declaration
public Task DeleteExpiredEntriesAsync(DateTimeOffset expirationDate, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTimeOffset | expirationDate | The expiration date threshold. Only events with an expiration date on or before this date will be deleted. |
| CancellationToken | cancellationToken | The cancellation token. |
Returns
| Type | Description |
|---|---|
| Task | A task that represents the asynchronous operation. |
Remarks
To prevent accidental deletion of recent events, the expiration date must be at least 1 year in the past.
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when the expiration date is too recent (less than 1 year in the past). |
GetAuditEventsAsync(AuditEventFilter, CancellationToken)
Asynchronously retrieves audit events that match the specified filter.
Declaration
public Task<IEnumerable<AuditEvent>> GetAuditEventsAsync(AuditEventFilter filter, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| AuditEventFilter | filter | The AuditEventFilter used to retrieve the audit events. |
| CancellationToken | cancellationToken | The cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<IEnumerable<AuditEvent>> | A task that represents the asynchronous operation. The task result contains the audit events. |
SetAuditEventAsync(AuditEvent, CancellationToken)
Asynchronously adds an audit event to the store.
Declaration
public Task SetAuditEventAsync(AuditEvent auditEvent, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| AuditEvent | auditEvent | The AuditEvent to add to the store. |
| CancellationToken | cancellationToken | The cancellation token. |
Returns
| Type | Description |
|---|---|
| Task | A task that represents the asynchronous operation. |
Remarks
This method performs the following operations:
- Validates that the ReferenceType is not empty.
- Sanitizes the Description to a maximum of 256 characters.
- Sanitizes the EventUrl to a maximum of 1000 characters.
- Populates missing values from the HTTP context and application settings.
- Sets expiration date to 2 years from the event date.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when auditEvent is null. |
| ArgumentException | Thrown when ReferenceType is null or empty. |