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.

Customize the Data Storing Mechanism

  • 5 minutes to read

The Audit Trail Module stores audit records (AuditDataItem objects) in an application database. The AuditTrailService.Instance.SaveAuditTrailData event allows you to configure how this Module saves information. This event is raised when the Module commits an AuditDataItem object to the database. In this event handler, you can modify the SaveAuditTrailDataEventArgs.AuditTrailDataItems collection, add new or remove unnecessary items. The following code demonstrates how to remove ObjectCreated records.

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

using DevExpress.Persistent.AuditTrail;
// ...
static class Program {
    // ...
    static void Main() {
        MySolutionWindowsFormsApplication application = new MySolutionWindowsFormsApplication();
        // ...
        AuditTrailService.Instance.SaveAuditTrailData += 
            new SaveAuditTrailDataEventHandler(Instance_SaveAuditTrailData);
        application.Setup();
        application.Start();
        // ...
    }
    static void Instance_SaveAuditTrailData(object sender, SaveAuditTrailDataEventArgs e) {
        for(int i = e.AuditTrailDataItems.Count - 1; i >= 0; i--) {
            var item = e.AuditTrailDataItems[i];
            if(item.OperationType == AuditOperationType.ObjectCreated) {
                e.AuditTrailDataItems.RemoveAt(i);
            }
        }
    }
}

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

using DevExpress.Persistent.AuditTrail;
// ...
public class Global : System.Web.HttpApplication {
    // ...
    protected void Session_Start(object sender, EventArgs e) {
        WebApplication.SetInstance(Session, new MySolutionWebApplication());
        AuditTrailService.Instance.SaveAuditTrailData += 
            new SaveAuditTrailDataEventHandler(Instance_SaveAuditTrailData);
        // ...
        WebApplication.Instance.Setup();
        WebApplication.Instance.Start();
    }
    static void Instance_SaveAuditTrailData(object sender, SaveAuditTrailDataEventArgs e) {
        for(int i = e.AuditTrailDataItems.Count - 1; i >= 0; i--) {
            var item = e.AuditTrailDataItems[i];
            if(item.OperationType == AuditOperationType.ObjectCreated) {
                e.AuditTrailDataItems.RemoveAt(i);
            }
        }
    }
}

XAF Blazor Application - Program.cs file:

using DevExpress.Persistent.AuditTrail;
// ...
public class Program
    public static void Main() {
        // ...
        AuditTrailService.Instance.SaveAuditTrailData += 
            new SaveAuditTrailDataEventHandler(Instance_SaveAuditTrailData);
        CreateHostBuilder(args).Build().Run();
    }
    static void Instance_SaveAuditTrailData(object sender, SaveAuditTrailDataEventArgs e) {
        for(int i = e.AuditTrailDataItems.Count - 1; i >= 0; i--) {
            var item = e.AuditTrailDataItems[i];
            if(item.OperationType == AuditOperationType.ObjectCreated) {
                e.AuditTrailDataItems.RemoveAt(i);
            }
        }
    }
}

Replace the Default Data Storing Mechanism with a Custom One

To do this, set the event's SaveAuditTrailDataEventArgs.Handled argument to true in the SaveAuditTrailData event handler.

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

using DevExpress.Persistent.AuditTrail;
// ...
static class Program {
    // ...
    static void Main() {
        MySolutionWindowsFormsApplication application = new MySolutionWindowsFormsApplication();
        // ...
        AuditTrailService.Instance.SaveAuditTrailData += 
            new SaveAuditTrailDataEventHandler(Instance_SaveAuditTrailData);
        application.Setup();
        application.Start();
        // ...
    }
    static void Instance_SaveAuditTrailData(object sender, SaveAuditTrailDataEventArgs e) {
        // Save the data passed as the e.AuditTrailDataItems parameter
        e.Handled = true; // Disable the default data storing mechanism
    }
}

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

using DevExpress.Persistent.AuditTrail;
// ...
public class Global : System.Web.HttpApplication {
    // ...
    protected void Session_Start(object sender, EventArgs e) {
        WebApplication.SetInstance(Session, new MySolutionWebApplication());
        AuditTrailService.Instance.SaveAuditTrailData += 
            new SaveAuditTrailDataEventHandler(Instance_SaveAuditTrailData);
        // ...
        WebApplication.Instance.Setup();
        WebApplication.Instance.Start();
    }
    static void Instance_SaveAuditTrailData(object sender, SaveAuditTrailDataEventArgs e) {
        // Save the data passed as the e.AuditTrailDataItems parameter
        e.Handled = true; // Disable the default data storing mechanism
    }
}

XAF Blazor Application - Program.cs file:

using DevExpress.Persistent.AuditTrail;
// ...
public class Program
    public static void Main() {
        // ...
        AuditTrailService.Instance.SaveAuditTrailData += 
            new SaveAuditTrailDataEventHandler(Instance_SaveAuditTrailData);
        CreateHostBuilder(args).Build().Run();
    }
    static void Instance_SaveAuditTrailData(object sender, SaveAuditTrailDataEventArgs e) {
        // Save the data passed as the e.AuditTrailDataItems parameter 
        e.Handled = true; // Disable the default data storing mechanism
    }
}

Alternative Approaches