Miscellaneous Customizations of the Audit Trail System (XPO)

  • 3 minutes to read

Implement Custom Persistent Object to be Used as the Audit Data Storage

The Audit Trail Module uses the AuditDataItemPersistent class as the audit data storage. To store extra audit information, inherit from this class or implement the IAuditDataItemPersistent interface. In the overridden OnSaving method of your AuditDataItemPersistent descendant, initialize extra properties based on the AuditedObject, PropertyName, and other info from the base class. Set the AuditDataItemPersistentType property to your class to use it instead of the default class.

Specify the String Representation of the Null Value

The Audit Trail Module saves the null value as the “N/A” string. To change its string representation, navigate to the Localization | AuditTrail node in the Model Editor and specify the NullValueString property.

If you want to use a different null value representation in audit records in the UI, set AuditTrailService.Instance.AuditDataStore‘s NullValueString property in the overridden XafApplication.OnSetupComplete method. The following example demonstrates how to do this:

File: MySolution.Win\WinApplication.cs(.vb) or MySolution.Web\WebApplication.cs(.vb).

using DevExpress.Persistent.AuditTrail;
// ...
public partial class MySolutionWinApplication : WinApplication {
    //...
    protected override void OnSetupComplete() {
        base.OnSetupComplete();
        AuditTrailService.Instance.AuditDataStore.NullValueString = "";
    }
    // ...
}

Customize the Blob Properties Storage Mechanism

The Audit Trail Module saves Blob property values as the “Blob data” string. Follow the steps below to customize this behavior.

Note

You can also use this technique to specify the string representation of reference type properties.

  1. Implement the AuditDataStore descendant and override its GetDefaultStringRepresentation method.

    File: MySolution.Module\CustomAuditDataStore.cs(.vb).

    using DevExpress.Persistent.AuditTrail;
    using DevExpress.Persistent.BaseImpl;
    // ...
    public class CustomAuditDataStore : AuditDataStore<AuditDataItemPersistent, AuditedObjectWeakReference> {
        protected override string GetDefaultStringRepresentation(object value) {
            string result = base.GetDefaultStringRepresentation(value);
            if(result == BlobDataString)
                return GetCustomBlobDataString(value);
            return result;
        }
    
        private string GetCustomBlobDataString(object value) {
            // ...  
        }
    }
    
  2. Set the AuditTrailService.Instance.AuditDataStore property to an instance of your class.

    File: MySolution.Win\WinApplication.cs(.vb) or MySolution.Web\WebApplication.cs(.vb).

    using DevExpress.Persistent.AuditTrail;
    // ...
    public partial class MySolutionWinApplication : WinApplication {
        // ...
        protected override void OnSetupComplete() {
            AuditTrailService.Instance.AuditDataStore = new CustomAuditDataStore();
            base.OnSetupComplete();
        }
        // ...
    }
    
See Also