Interface IAuditLogsApi
- Namespace
- Cloudflare.NET.AuditLogs
- Assembly
- Cloudflare.NET.dll
Defines the contract for audit log operations.
Audit logs provide a record of actions taken on account and user resources. Logs are retained for 30 days. This interface handles both account-scoped and user-scoped audit logs.
public interface IAuditLogsApi
Methods
GetAccountAuditLogsAsync(string, ListAuditLogsFilters?, CancellationToken)
Gets audit logs for the account.
Note: Audit logs are only available for the past 30 days. This is a beta API and error handling may be incomplete.
Task<CursorPaginatedResult<AuditLog>> GetAccountAuditLogsAsync(string accountId, ListAuditLogsFilters? filters = null, CancellationToken cancellationToken = default)
Parameters
accountIdstringThe account identifier.
filtersListAuditLogsFiltersOptional filtering and pagination options.
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<CursorPaginatedResult<AuditLog>>
A page of audit logs with cursor information.
Examples
// Get recent audit logs
var logs = await client.AuditLogs.GetAccountAuditLogsAsync(accountId,
new ListAuditLogsFilters(
Since: DateTime.UtcNow.AddDays(-7),
Limit: 100));
foreach (var log in logs.Items)
{
Console.WriteLine($"{log.Action.Time}: {log.Action.Type} by {log.Actor.Email}");
}
Exceptions
- ArgumentException
Thrown when
accountIdis null or whitespace.- HttpRequestException
Thrown when the API returns an HTTP error status code.
- CloudflareApiException
Thrown when the API returns a non-success response.
GetAllAccountAuditLogsAsync(string, ListAuditLogsFilters?, CancellationToken)
Gets all audit logs for the account, automatically handling pagination.
Note: Audit logs are only available for the past 30 days. Consider using time filters to limit results for large accounts.
IAsyncEnumerable<AuditLog> GetAllAccountAuditLogsAsync(string accountId, ListAuditLogsFilters? filters = null, CancellationToken cancellationToken = default)
Parameters
accountIdstringThe account identifier.
filtersListAuditLogsFiltersOptional filtering options. Cursor is ignored.
cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<AuditLog>
An async enumerable of all matching audit logs.
Examples
// Get all failed actions in the last week
var filters = new ListAuditLogsFilters(
Since: DateTime.UtcNow.AddDays(-7),
ActionResults: new[] { "failure" });
await foreach (var log in client.AuditLogs.GetAllAccountAuditLogsAsync(accountId, filters))
{
Console.WriteLine($"Failed: {log.Action.Type} - {log.Action.Description}");
}
Exceptions
- ArgumentException
Thrown when
accountIdis null or whitespace.- HttpRequestException
Thrown when the API returns an HTTP error status code.
- CloudflareApiException
Thrown when the API returns a non-success response.
ListAllUserAuditLogsAsync(ListAuditLogsFilters?, CancellationToken)
Gets all audit logs for the authenticated user, automatically handling pagination.
Audit logs are only available for the past 30 days. Consider using time filters to limit results for active users.
IAsyncEnumerable<AuditLog> ListAllUserAuditLogsAsync(ListAuditLogsFilters? filters = null, CancellationToken cancellationToken = default)
Parameters
filtersListAuditLogsFiltersOptional filtering options. Cursor is ignored.
cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<AuditLog>
An async enumerable of all matching user audit logs.
Examples
// Get all failed actions in the last week
var filters = new ListAuditLogsFilters(
Since: DateTime.UtcNow.AddDays(-7),
ActionResults: new[] { "failure" });
await foreach (var log in client.AuditLogs.ListAllUserAuditLogsAsync(filters))
{
Console.WriteLine($"Failed: {log.Action.Type} - {log.Action.Description}");
}
Exceptions
- HttpRequestException
Thrown when the API returns an HTTP error status code.
- CloudflareApiException
Thrown when the API returns a non-success response.
ListUserAuditLogsAsync(ListAuditLogsFilters?, CancellationToken)
Gets audit logs for actions taken by the authenticated user.
Audit logs are only available for the past 30 days. Shows actions taken by the user across all their accounts.
Task<CursorPaginatedResult<AuditLog>> ListUserAuditLogsAsync(ListAuditLogsFilters? filters = null, CancellationToken cancellationToken = default)
Parameters
filtersListAuditLogsFiltersOptional filtering and pagination options.
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<CursorPaginatedResult<AuditLog>>
A page of audit logs with cursor information.
Examples
// Get recent user audit logs
var logs = await client.AuditLogs.ListUserAuditLogsAsync(
new ListAuditLogsFilters(
Since: DateTime.UtcNow.AddDays(-7),
Limit: 100));
foreach (var log in logs.Items)
{
Console.WriteLine($"{log.Action.Time}: {log.Action.Type} by {log.Actor.Email}");
}
Exceptions
- HttpRequestException
Thrown when the API returns an HTTP error status code.
- CloudflareApiException
Thrown when the API returns a non-success response.