Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

Add Custom Data to the Audit Log

Object changes are represented by AuditDataItem objects (see Audit Trail Module Overview). You can add custom data (information on events that are not audited) to the audit log directly. This means that you can add an AuditDataItem object to the Audit Data Items collection. For this purpose, specify the following code.

using DevExpress.ExpressApp;
using DevExpress.Persistent.AuditTrail;
using DevExpress.Xpo;
using Microsoft.Extensions.DependencyInjection;
// ...
var auditTrailService = serviceProvider.GetRequiredService<AuditTrailService>();
AuditDataItem customDataItem = new AuditDataItem(myAuditedObject, null, 
    "CustomOldValue", "CustomNewValue", AuditOperationType.CustomData);
auditTrailService.AddCustomAuditData(mySession, customDataItem);
auditTrailService.SaveAuditData(mySession);

This code can be implemented at any point in a program. For instance, in a custom Controller.

Note

You should always invoke the SaveAuditData method after adding custom audit data manually, without reusing the Session of the View’s ObjectSpace. Otherwise, the audit data will not be written to the database.