Add Custom Data to the Audit Log
Object changes are stored as AuditDataItem objects (see Audit Trail Module Overview). You can add custom data (information on events that are not audited) to the audit log directly by adding an AuditDataItem object to the Audit Data Items collection. The following code snippet demonstrates this scenario:
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);
You can implement this code at any point in a program, for example, 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.