Skip to content

Audit Logging

This Audit Logging Module provides a comprehensive audit logging solution to track all user actions and data changes within the application.

Enabling Auditing

UseAuditing() middleware should be added to the ASP.NET Core request pipeline in order to create and save the audit logs.

public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
    var app = context.GetApplicationBuilder();
    var env = context.GetEnvironment();
    ...
    app.UseAuditing();
    ...
}

For more details on configuration and advanced settings, please see our Audit Logging documentation.

User Interface

This module provides MVC/Razor Pages UI.

This module adds an Audit logs menu item under the Administration menu:

menu

  • Audit logs: List, view and filter audit logs and entity changes.

AuditLoggingMenus class has the constants for the menu item names.

Features

This section covers some other features provided by this module.

Audit Logs

Audit logs tab is used to list, view and filter audit logs and entity changes in the system.

audit-logs

Each line on the list contains basic information about an audit log like HTTP Status Code, HTTP Method, Execution Time etc...

Audit Log Details

You can view details of an audit log by clicking the button on each audit log line:

audit-logs

  • Overall: This tab contains detailed information about audit log.
  • Actions: This tab shows list of actions (controller actions and application service method calls with their parameters) executed during a web request.
  • Changes: This tab shows changed entities during the web request.

Export to Excel

You can export audit logs to Excel by clicking the "Export to Excel" button in the toolbar. If the result set is small (less than a configurable threshold), the file will be generated and downloaded immediately. For larger result sets, the export will be processed as a background job and you'll receive an email with a download link once the export is completed.

Entity Changes

Entity changes tab is used to list, view and filter entity change logs.

Saving all changes of all your entities would require a lot of database space. For this reason, audit log system doesn't save any change for the entities unless you explicitly configure it.

Configure<AbpAuditingOptions>(options =>
{
    options.EntityHistorySelectors.AddAllEntities();
});

entity-change

Each line on the list contains basic information about an entity change log like Time (time of change), Change Type etc...

Audit Log Settings

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.

settings

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.

Options

AbpAuditingOptions

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

ExpiredAuditLogDeleterOptions can be configured in the UI layer, within theConfigureServices 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.ExcelFileCleanupOptions.CronExpression = "0 23 * * *"; // Quartz Cron expression is "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

AuditLogExcelFileOptions can be configured in the application layer, within the ConfigureServices method of your module. Example:

Configure<AuditLogExcelFileOptions>(options =>
{
    options.FileRetentionInHours = 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)
    options.ExcelFileCleanupOptions.CronExpression = "0 23 * * *"; // Quartz Cron expression is "0 23 * * * ?"
});