Skip to main content
Version: 4.0.0

Overview

The @abpjs/audit-logging package provides components and services for viewing and managing audit logs in ABP React applications. This is the React equivalent of Angular's @volo/abp.ng.audit-logging module.

npm version

ABP Commercial License Required

This package is free to use but requires the corresponding backend module from ABP Commercial. You can purchase an ABP Commercial license from abp.io.

Installation

npm install @abpjs/audit-logging
# or
yarn add @abpjs/audit-logging

Required peer dependencies:

npm install @abpjs/core @abpjs/theme-shared @chakra-ui/react

Features

  • Audit Logs Table - Paginated table with filtering and sorting
  • Log Details Modal - View detailed audit log information
  • Entity Changes - Track entity property changes
  • Action Tracking - View service method calls and parameters
  • Statistics - Average execution duration and error rate charts
  • Advanced Filtering - Filter by user, URL, HTTP method, status code, and more

Main Exports

Components

ComponentDescription
AuditLogsComponentComplete audit logs management UI

Hooks

HookDescription
useAuditLogsHook for managing audit log state and operations

Services

ServiceDescription
AuditLogsServiceProxy service for audit logging API (v3.2.0+)
AuditLoggingStateServiceState management with dispatch methods (v2.0.0)
EntityChangeModalServiceEntity change detail/history modals (v3.0.0)

Constants

ConstantDescription
AUDIT_LOGGING_ROUTESPre-configured routes
HTTP_METHODSList of HTTP methods for filtering
HTTP_STATUS_CODESList of HTTP status codes with descriptions

Quick Example

import { AuditLogsComponent } from '@abpjs/audit-logging';

function AuditLogsPage() {
return (
<AuditLogsComponent
onAuditLogSelected={(log) => console.log('Selected:', log)}
/>
);
}

Using the Hook

import { useAuditLogs } from '@abpjs/audit-logging';
import { useEffect } from 'react';

function CustomAuditLogs() {
const {
auditLogs,
totalCount,
isLoading,
error,
fetchAuditLogs,
getAuditLogById,
fetchAverageExecutionStats,
fetchErrorRateStats,
} = useAuditLogs();

useEffect(() => {
fetchAuditLogs({
maxResultCount: 10,
skipCount: 0,
});
}, []);

if (isLoading) return <div>Loading...</div>;
if (error) return <div>Error: {error}</div>;

return (
<div>
<h2>Audit Logs ({totalCount})</h2>
<ul>
{auditLogs.map((log) => (
<li key={log.id}>
{log.userName} - {log.httpMethod} {log.url} ({log.httpStatusCode})
</li>
))}
</ul>
</div>
);
}

Hook Return Values

PropertyTypeDescription
auditLogsAuditLogDto[]List of audit logs
totalCountnumberTotal count for pagination
selectedLogAuditLogDto | nullCurrently selected log
isLoadingbooleanLoading state
errorstring | nullError message
averageExecutionStatsRecord<string, number>Execution duration statistics
errorRateStatsRecord<string, number>Error rate statistics
sortKeystringCurrent sort field
sortOrder'asc' | 'desc' | ''Sort direction
fetchAuditLogs(params?: GetAuditLogListDto) => PromiseFetch audit logs with params
getAuditLogById(id: string) => PromiseGet single log by ID
fetchAverageExecutionStats(params: GetAverageExecutionDurationPerDayInput) => PromiseFetch execution stats
fetchErrorRateStats(params: GetErrorRateFilter) => PromiseFetch error rate stats
setSelectedLogfunctionSet selected log
setSortKeyfunctionUpdate sort field
setSortOrderfunctionUpdate sort direction
resetfunctionReset all state

Service Methods

The AuditLogsService provides the following methods:

MethodParametersReturnsDescription
getListparams?: GetAuditLogListDtoPromise<PagedResultDto<AuditLogDto>>Get paginated audit logs
getid: stringPromise<AuditLogDto>Get single audit log
getAverageExecutionDurationPerDayparams: GetAverageExecutionDurationPerDayInputPromise<GetAverageExecutionDurationPerDayOutput>Get execution duration stats
getErrorRateparams: GetErrorRateFilterPromise<GetErrorRateOutput>Get error rate stats
getEntityChangeid: stringPromise<EntityChangeDto>Get single entity change
getEntityChangeWithUsernameid: stringPromise<EntityChangeWithUsernameDto>Get entity change with username
getEntityChangesparams: GetEntityChangesDtoPromise<PagedResultDto<EntityChangeDto>>Get paginated entity changes
getEntityChangesWithUsernameparams: EntityChangeFilterPromise<EntityChangeWithUsernameDto[]>Get entity changes with username

Query Parameters

Filter audit logs with GetAuditLogListDto:

import type { GetAuditLogListDto } from '@abpjs/audit-logging';

const params: GetAuditLogListDto = {
// Pagination
skipCount: 0,
maxResultCount: 10,
sorting: 'executionTime desc',

// Filters
url: '/api/users',
userName: 'admin',
applicationName: 'MyApp',
correlationId: 'abc-123',
httpMethod: 'POST',
httpStatusCode: 200,
minExecutionDuration: 100,
maxExecutionDuration: 5000,
hasException: false,
startTime: '2026-01-01T00:00:00Z',
endTime: '2026-01-31T23:59:59Z',
};

Routes

import { AUDIT_LOGGING_ROUTES } from '@abpjs/audit-logging';

// Route configuration:
// /audit-logs (requires 'AuditLogging.AuditLogs' policy)

HTTP Constants

import { HTTP_METHODS, HTTP_STATUS_CODES } from '@abpjs/audit-logging';

// HTTP_METHODS: ['GET', 'POST', 'DELETE', 'PUT', 'HEAD', 'CONNECT', 'OPTIONS', 'TRACE', 'PATCH']

// HTTP_STATUS_CODES: [{ code: 200, message: 'OK' }, { code: 404, message: 'Not Found' }, ...]

TypeScript Support

import type {
// Audit Log DTOs
AuditLogDto,
AuditLogActionDto,
GetAuditLogListDto,
// Entity Change DTOs
EntityChangeDto,
EntityChangeWithUsernameDto,
EntityPropertyChangeDto,
GetEntityChangesDto,
EntityChangeFilter,
// Statistics DTOs
GetAverageExecutionDurationPerDayInput,
GetAverageExecutionDurationPerDayOutput,
GetErrorRateFilter,
GetErrorRateOutput,
// State
AuditLogging, // AuditLogging.State
HttpStatusCode,
} from '@abpjs/audit-logging';

Required Policies

The audit logging module requires the following ABP policies:

PolicyDescription
AuditLogging.AuditLogsView audit logs

Dependencies

  • @abpjs/core - Core ABP React functionality
  • @abpjs/theme-shared - Shared UI components
  • @chakra-ui/react - UI component library

See Also