Skip to main content

Audit Specific Operations

  • 3 minutes to read

You can instruct Audit Trail Module not to log particular operations. Handle the CustomizeAuditOperationTypeFilter event, check the current operation type, and set the SaveAuditOperation argument to false. The following example shows how to exclude the ObjectChanged and ObjectCreated records from the audit log.

In a Cross-Platform Module

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

using DevExpress.Persistent.AuditTrail;
using static DevExpress.Persistent.AuditTrail.AuditTrailService;
// ...
public sealed partial class MySolutionModule : ModuleBase { 
    public override void Setup(XafApplication application) {
        base.Setup(application); 
        AuditTrailService.Instance.CustomizeAuditOperationTypeFilter += 
            new EventHandler<CustomAuditOperationTypeFilterEventArgs>(Instance_CustomizeAuditOperationTypeFilter);  
        //...  
    }  
    private static void Instance_CustomizeAuditOperationTypeFilter(object sender, CustomAuditOperationTypeFilterEventArgs e) {  
        if(e.AuditOperationType == AuditOperationType.ObjectChanged || 
            e.AuditOperationType == AuditOperationType.ObjectCreated) {
            e.SaveAuditOperation = false;
        }
    }
    // ...
}  

In a WinForms Application

File: Program.cs (Program.vb).

using DevExpress.Persistent.AuditTrail;
using static DevExpress.Persistent.AuditTrail.AuditTrailService;
// ...
public class Program {  
    public static void Main() {  
        //...  
        MySolutionWinApplication winApplication = new MySolutionWinApplication();  
        AuditTrailService.Instance.CustomizeAuditOperationTypeFilter += 
            new EventHandler<CustomAuditOperationTypeFilterEventArgs>(Instance_CustomizeAuditOperationTypeFilter);  
        //...  
    }  
    private static void Instance_CustomizeAuditOperationTypeFilter(object sender, CustomAuditOperationTypeFilterEventArgs e) {  
        if(e.AuditOperationType == AuditOperationType.ObjectChanged || 
            e.AuditOperationType == AuditOperationType.ObjectCreated) {
            e.SaveAuditOperation = false;
        }
    }
    // ...
}  

In an ASP.NET Web Forms Application

File: Global.asax.cs (Global.asax.vb).

using DevExpress.Persistent.AuditTrail;
using static DevExpress.Persistent.AuditTrail.AuditTrailService;
// ...
public class Global : System.Web.HttpApplication {
    protected void Session_Start(object sender, EventArgs e) {
        //...  
        WebApplication.SetInstance(Session, new MySolutionWebApplication());  
        AuditTrailService.Instance.CustomizeAuditOperationTypeFilter += 
            new EventHandler<CustomAuditOperationTypeFilterEventArgs>(Instance_CustomizeAuditOperationTypeFilter);  
        //...  
    }  
    private static void Instance_CustomizeAuditOperationTypeFilter(object sender, CustomAuditOperationTypeFilterEventArgs e) {  
        if(e.AuditOperationType == AuditOperationType.ObjectChanged || 
            e.AuditOperationType == AuditOperationType.ObjectCreated) {
            e.SaveAuditOperation = false;
        }
    }
    // ...
} 

In an ASP.NET Core Blazor Application

File: Program.cs.

using DevExpress.Persistent.AuditTrail;
using static DevExpress.Persistent.AuditTrail.AuditTrailService;
// ...
public class Program {  
    public static void Main() {  
        //...    
        AuditTrailService.Instance.CustomizeAuditOperationTypeFilter += 
            new EventHandler<CustomAuditOperationTypeFilterEventArgs>(Instance_CustomizeAuditOperationTypeFilter);  
        CreateHostBuilder(args).Build().Run();
    }  
    private static void Instance_CustomizeAuditOperationTypeFilter(object sender, CustomAuditOperationTypeFilterEventArgs e) {  
        if(e.AuditOperationType == AuditOperationType.ObjectChanged || 
            e.AuditOperationType == AuditOperationType.ObjectCreated) {
            e.SaveAuditOperation = false;
        }
    }
    // ...
}