All docs
V20.2
20.2
20.1
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

Specify the Objects and Properties to Be Audited

  • 2 minutes to read

You can modify default audit settings, and specify objects and properties to be audited or excluded from the audit process. For this purpose, subscribe to the CustomizeAuditTrailSettings event of a AuditTrailService.Instance object. The following code demonstrates how this can be implemented.

XAF Windows Forms Application - Program.cs (Program.vb) file:

using DevExpress.Persistent.AuditTrail;
//...
static void Main() {
    MySolutionWindowsFormsApplication application = new MySolutionWindowsFormsApplication();
    // ...
    AuditTrailService.Instance.CustomizeAuditTrailSettings += 
        new CustomizeAuditSettingsEventHandler(Instance_CustomizeAuditTrailSettings);
    application.Setup();
    application.Start();
    //...
}
static void Instance_CustomizeAuditTrailSettings(object sender, 
    CustomizeAuditTrailSettingsEventArgs e) {
    e.AuditTrailSettings.Clear();
    e.AuditTrailSettings.AddType(typeof(MyObjectType), "FirstPropertyToBeAudited", "SecondPropertyToBeAudited");
}

XAF ASP.NET Application - Global.asax.cs (Global.asax.vb) file:

using DevExpress.Persistent.AuditTrail;
//...
protected void Session_Start(object sender, EventArgs e) {
    WebApplication.SetInstance(Session, new MySolutionWebApplication());
    AuditTrailService.Instance.CustomizeAuditTrailSettings += 
        new CustomizeAuditSettingsEventHandler(Instance_CustomizeAuditTrailSettings);
    //...
    WebApplication.Instance.Setup();
    WebApplication.Instance.Start();
}
void Instance_CustomizeAuditTrailSettings(object sender, 
    CustomizeAuditTrailSettingsEventArgs e) {
    e.AuditTrailSettings.Clear();
    e.AuditTrailSettings.AddType(typeof(MyObjectType), "FirstPropertyToBeAudited", "SecondPropertyToBeAudited");
}

Take note of the CustomizeAuditTrailSettings event handler. The default settings are removed by the AuditTrailSettings.Clear method. The properties to audit are added by the AuditTrailSettings.AddType method. You can use another overload of this method, which does not require specifying members names.

e.AuditTrailSettings.AddType(typeof(MyObjectType));

All members owned by the class, which are public and not read-only, will be audited. If MyObjectType exposes a read-only property to be audited, add it manually.

e.AuditTrailSettings.AddType(typeof(MyObjectType), "ReadOnlyPropertyToBeAudited");

The AuditTrailSettings.RemoveProperties method is used to exclude properties from the audit process.

e.AuditTrailSettings.RemoveProperties(typeof(MyObjectType), "PropertyToBeExcluded");

You can use the CustomizeAuditTrailSettings event to customize the AuditTrailSettings object in other ways. For example, you can specify properties that are not to be audited. For this purpose, use the AuditTrailSettings.RemoveProperties method.