docs/en/modules/audit-logging-pro.md
//[doc-seo]
{
"Description": "Discover the ABP Framework's Audit Logging Module (Pro) to track changes, filter logs, and enhance application monitoring efficiently."
}
You must have an ABP Team or a higher license to use this module.
This module implements the Audit Logging system of an application;
See the module description page for an overview of the module features.
Audit Logging is pre-installed in the startup templates. So, no need to manually install it.
This module follows the module development best practices guide and consists of several NuGet and NPM packages. See the guide if you want to understand the packages and relations between them.
You can visit Audit Logging module package list page to see list of packages related with this module.
Audit logs module adds the following items to the "Main" menu, under the "Administration" menu item:
AbpAuditLoggingMainMenuNames class has the constants for the menu item names.
Audit logs tab is used to list, view and filter audit logs and entity changes in the system.
Each line on the list contains basic information about an audit log like HTTP Status Code, HTTP Method, Execution Time etc...
You can view details of an audit log by clicking the magnifier icon on each audit log line:
You can export audit logs to Excel by clicking the "Export to Excel" button in the toolbar. The file is generated and downloaded immediately when the result set contains 1,000 records or fewer. If the result set contains more than 1,000 records, the export is processed as a background job and you'll receive an email with a download link once the export is completed.
Entity changes tab is used to list, view and filter entity change logs.
Blazor Server note: Entity change history can be missing or incomplete in some
Blazor Serverscenarios due to known SignalR/event-pipeline limitations. See Audit Logging and #11682.
Each line on the list contains basic information about an entity change log like Time (time of change), Change Type etc...
You can view details of an entity change log by clicking the "Change Details" action item in the entity change log list:
You can view details of all changes of an entity by clicking the "Full Change History" action item in the entity change log list:
You can export entity changes to Excel by clicking the "Export to Excel" button in the toolbar. As with audit log exports, result sets with 1,000 records or fewer are downloaded immediately. Result sets with more than 1,000 records are processed as a background job, and you'll receive an email notification once the export is completed.
The Audit Log settings tab is used to configure audit log settings. You can enable or disable the clean up service system wide. This way, you can shut down the clean up service for all tenants and host. If the system wide clean up service is enabled, you can configure the global Expired Item Deletion Period for all tenants and host.
When configuring the global settings for the audit log module from the host side in this manner, ensure that each tenant and host uses the global values. If you want to set tenant/host-specific values, you can do so under Settings -> Audit Log -> General. This way, you can disable the clean up service for specific tenants or host. It overrides the global settings.
To view the audit log settings, you need to enable the feature. For the host side, navigate to Settings -> Feature Management -> Manage Host Features -> Audit Logging -> Enable audit log setting management. For the tenant side, you can use either Tenant Features or Edition Features.
If you don't enable the Cleanup Service System Wide from the host side under Settings -> Audit logs -> Global, it won't remove the expired audit logs, even if there are tenant specific settings.
The module provides Error Rate and Average Execution Duration Per Day widgets. The current user needs the AuditLogging.AuditLogs permission to load their data.
Import the widget components from @volo/abp.ng.audit-logging, add them to your component imports and keep references when you need to refresh their date range:
import { Component, ViewChild } from '@angular/core';
import {
AverageExecutionDurationWidgetComponent,
ErrorRateWidgetComponent,
} from '@volo/abp.ng.audit-logging';
@Component({
selector: 'app-audit-statistics',
templateUrl: './audit-statistics.component.html',
imports: [
AverageExecutionDurationWidgetComponent,
ErrorRateWidgetComponent,
],
})
export class AuditStatisticsComponent {
@ViewChild('averageExecutionDurationWidget')
averageExecutionDurationWidget!: AverageExecutionDurationWidgetComponent;
@ViewChild('errorRateWidget')
errorRateWidget!: ErrorRateWidgetComponent;
refresh(startDate: string, endDate: string) {
this.averageExecutionDurationWidget.draw({ startDate, endDate });
this.errorRateWidget.draw({ startDate, endDate });
}
}
The width and height inputs are optional. Both default to 273 and 136, respectively.
<abp-average-execution-duration-widget
#averageExecutionDurationWidget
[height]="250"
></abp-average-execution-duration-widget>
<abp-error-rate-widget
#errorRateWidget
[height]="250"
></abp-error-rate-widget>
The Bootstrap and MudBlazor packages expose components with the same parameters and RefreshAsync method. The following example uses the Bootstrap Blazor package. For MudBlazor, use the corresponding Volo.Abp.AuditLogging.Blazor.MudBlazor namespaces.
@using Volo.Abp.AuditLogging.Blazor.Pages.Shared.AverageExecutionDurationPerDayWidget
@using Volo.Abp.AuditLogging.Blazor.Pages.Shared.ErrorRateWidget
<AuditLoggingAverageExecutionDurationPerDayWidgetComponent
@bind-StartDate="@StartDate"
@bind-EndDate="@EndDate"
@ref="AverageExecutionDurationWidget" />
<AuditLoggingErrorRateWidgetComponent
@bind-StartDate="@StartDate"
@bind-EndDate="@EndDate"
@ref="ErrorRateWidget" />
@code {
private DateTime StartDate { get; set; } = DateTime.Today.AddMonths(-1);
private DateTime EndDate { get; set; } = DateTime.Today;
private AuditLoggingAverageExecutionDurationPerDayWidgetComponent AverageExecutionDurationWidget { get; set; } = default!;
private AuditLoggingErrorRateWidgetComponent ErrorRateWidget { get; set; } = default!;
private async Task RefreshAsync()
{
await AverageExecutionDurationWidget.RefreshAsync();
await ErrorRateWidget.RefreshAsync();
}
}
Use IWidgetManager to check the widget permission before invoking its view component:
@using Volo.Abp.AspNetCore.Mvc.UI.Widgets
@using Volo.Abp.AuditLogging.Web.Pages.Shared.Components.AverageExecutionDurationPerDayWidget
@using Volo.Abp.AuditLogging.Web.Pages.Shared.Components.ErrorRateWidget
@inject IWidgetManager WidgetManager
@if (await WidgetManager.IsGrantedAsync(typeof(AuditLoggingErrorRateWidgetViewComponent)))
{
@await Component.InvokeAsync(typeof(AuditLoggingErrorRateWidgetViewComponent))
}
@if (await WidgetManager.IsGrantedAsync(typeof(AuditLoggingAverageExecutionDurationPerDayWidgetViewComponent)))
{
@await Component.InvokeAsync(typeof(AuditLoggingAverageExecutionDurationPerDayWidgetViewComponent))
}
This module doesn't seed any data.
AbpAuditingOptions can be configured in the UI layer, in the ConfigureServices method of your module. Example:
Configure<AbpAuditingOptions>(options =>
{
//Set options here...
});
To see AbpAuditingOptions properties, please see its documentation.
ExpiredAuditLogDeleterOptions can be configured in the UI layer, within the ConfigureServices method of your module. Example:
Configure<ExpiredAuditLogDeleterOptions>(options =>
{
options.Period = (int)TimeSpan.FromSeconds(30).TotalMilliseconds;
// This Cron expression only works if Hangfire or Quartz is used for background workers.
// The Hangfire Cron expression is different from the Quartz Cron expression, Please refer to the following links:
// https://www.quartz-scheduler.net/documentation/quartz-3.x/tutorial/crontriggers.html#cron-expressions
// https://docs.hangfire.io/en/latest/background-methods/performing-recurrent-tasks.html
options.CronExpression = "0 23 * * *"; // Quartz Cron expression is "0 0 23 * * ?"
});
The Period doesn't mean the Expired Item Deletion Period. It's the period of the worker to run clean up service system wide. The default value is 1 day.
AuditLogExcelFileOptions can be configured in the UI layer, within the ConfigureServices method of your module. Example:
Configure<AuditLogExcelFileOptions>(options =>
{
options.FileRetentionHours = 24; // How long to keep files before cleanup (default: 24 hours)
options.DownloadBaseUrl = "https://yourdomain.com"; // Base URL for download links in emails
options.ExcelFileCleanupOptions.Period = (int)TimeSpan.FromHours(24).TotalMilliseconds; // Interval of the cleanup worker (default: 24 hours)
// This Cron expression only works if Hangfire or Quartz is used for background workers.
// The Hangfire Cron expression is different from the Quartz Cron expression, Please refer to the following links:
// https://www.quartz-scheduler.net/documentation/quartz-3.x/tutorial/crontriggers.html#cron-expressions
// https://docs.hangfire.io/en/latest/background-methods/performing-recurrent-tasks.html
options.ExcelFileCleanupOptions.CronExpression = "0 23 * * *"; // Quartz Cron expression is "0 0 23 * * ?"
});
Note: The
FileRetentionHoursvalue determines when files become eligible for deletion, but actual deletion depends on when the cleanup worker runs. If the worker hasn't run after the retention period expires, files will remain accessible. Therefore,FileRetentionHoursrepresents the minimum intended retention time, but the actual retention time might be longer depending on the worker's execution schedule.
These settings control where Excel export files are stored, how long they are kept before automatic cleanup, and what base URL is used in email download links.
You must use a valid BLOB Storage Provider to use this feature.
This module follows the Entity Best Practices & Conventions guide.
An audit log is a security-relevant chronological record, set of records, and/or destination and source of records that provide documentary evidence of the sequence of activities that have affected at any time a specific operation, procedure, or event.
AuditLog (aggregate root): Represents an audit log in the system.
EntityChange (collection): Changed entities of audit log.AuditLogAction (collection): Executed actions of audit log.This module follows the Repository Best Practices & Conventions guide.
Following custom repositories are defined for this module:
IAuditLogRepositoryAuditLogsAppService (implements IAuditLogsAppService): Implements the use cases of the audit logs management UI.The module provides email templates for notifications:
AuditLogExportCompleted: Sent when an audit log export is successfully completed, including a download link.AuditLogExportFailed: Sent when an audit log export fails, including error details.EntityChangeExportCompleted: Sent when an entity change export is successfully completed, including a download link.EntityChangeExportFailed: Sent when an entity change export fails, including error details.All tables/collections use the Abp prefix by default. Set static properties on the AbpAuditLoggingDbProperties class if you need to change the table prefix or set a schema name (if supported by your database provider).
This module uses AbpAuditLogging for the connection string name. If you don't define a connection string with this name, it fallbacks to the Default connection string.
See the connection strings documentation for details.
The module defines the following feature and permission relationships:
AuditLogging.Enable is enabled by default. The AuditLogging.AuditLogs permission requires this feature, and the audit log application service also checks it.AuditLogging.SettingManagement is a child feature of AuditLogging.Enable and is disabled by default. The AuditLogging.AuditLogs.SettingManagement permission requires this feature.AuditLogging.AuditLogs.Export is a child permission of AuditLogging.AuditLogs. Audit log and entity change export operations require this permission.See the AbpAuditLoggingPermissions and AbpAuditLoggingFeatures class members for the complete definitions.
You can define a permission for the change history of a specific entity by using the AuditLogging.ViewChangeHistory:{EntityTypeFullName} naming convention. For example, the permission name for Acme.BookStore.Books.Book is AuditLogging.ViewChangeHistory:Acme.BookStore.Books.Book.
When a matching permission is defined and granted, the user can view that entity's change history. If the entity-specific permission is not defined or is not granted, authorization falls back to AuditLogging.AuditLogs. Users who have the general audit log permission can therefore still view the entity history.
In order to configure the application to use the audit logging module, you first need to import provideAuditLoggingConfig from @volo/abp.ng.audit-logging/config to root configuration. Then, you will need to append it to the appConfig array.
// app.config.ts
import { provideAuditLoggingConfig } from '@volo/abp.ng.audit-logging/config';
export const appConfig: ApplicationConfig = {
providers: [
// ...
provideAuditLoggingConfig(),
],
};
The audit logging module should be imported and lazy-loaded in your routing array. It has a static createRoutes method for configuration. Available options are listed below. It is available for import from @volo/abp.ng.audit-logging.
// app.routes.ts
export const APP_ROUTES: Routes = [
// ...
{
path: 'audit-logs',
loadChildren: () => import('@volo/abp.ng.audit-logging').then(c => c.createRoutes(/* options here */)),
},
];
<h4 id="h-audit-logging-module-options">Options</h4>If you have generated your project via the startup template, you do not have to do anything, because it already has both files configured.
You can modify the look and behavior of the module pages by passing the following options to createRoutes static method:
Audit Logging module services and models are generated via generate-proxy command of the ABP CLI. If you need the module's proxies, you can run the following command in the Angular project directory:
abp generate-proxy --module auditLogging
eAuditLoggingComponents enum provides all replaceable component keys. It is available for import from @volo/abp.ng.audit-logging.
Please check Component Replacement document for details.
The Audit Logging module remote endpoint URL can be configured in the environment files.
export const environment = {
// other configurations
apis: {
default: {
url: 'default url here',
},
AbpAuditLogging: {
url: 'Audit Logging remote url here'
}
// other api configurations
},
};
The Audit Logging module remote URL configuration shown above is optional. If you don't set a URL, the default.url will be used as fallback.
This module doesn't define any additional distributed event. See the standard distributed events.