Skip to main content
All docs
V25.2
  • Disable the Audit Trail Module

    • 2 minutes to read

    Disable the Module Permanently

    To disable the Audit Trail Module and stop tracking changes in your application, use the standard DbContextFactory instead of AuditedDbContext. Configure database context options for audited and not-audited contexts. Call the WithDbContext method to disable the Audit Trail Module or WithAuditedDbContext method to enable the module.

    Note

    With this technique, you cannot change the state of the Module during application execution.

    The following example demonstrates how to declare an additional UseStandardDbContectFactory field to switch between the audited and standard DbContext factories:

    bool UseStandardDbContectFactory = true;
    //...
    var dbContextServiceBuilder = builder.ObjectSpaceProviders
        .AddSecuredEFCore(options => options.PreFetchReferenceProperties());
    Action<IServiceProvider, DbContextOptionsBuilder> configureDbContextOptions = (serviceProvider, dbContextOptions) => {
        //your dbContextOptions configuration here
    };
    Action<IServiceProvider, DbContextOptionsBuilder> configureAuditedDbContextOptions = (serviceProvider, dbContextOptions) => {
        //your auditedDbContextOptions configuration here
    };
    if (UseStandardDbContectFactory) {
        dbContextServiceBuilder.WithDbContext<MySolution.Module.BusinessObjects.MySolutionEFCoreDbContext>(configureDbContextOptions);
    } else {
        dbContextServiceBuilder.WithAuditedDbContext(contexts => {
            contexts.Configure<MySolution.Module.BusinessObjects.MySolutionEFCoreDbContext, 
                MySolution.Module.BusinessObjects.MySolutionAuditingDbContext>(
                    configureDbContextOptions,
                    configureAuditedDbContextOptions);
        });
    }
    builder.ObjectSpaceProviders.AddNonPersistent();
    

    Disable the Module Temporarily

    The AuditTrailService.Enabled property allows you to disable the Audit Trail Module for a specific scenario. You can use this technique in different parts of your application (for example, in Controllers).

    The following example demonstrates this technique:

    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.Actions;
    using DevExpress.ExpressApp.EFCore;
    using DevExpress.Persistent.Base;
    using DevExpress.Persistent.BaseImpl.EFCore.AuditTrail;
    // ...
    public class CustomController : ViewController<DetailView> {
        public CustomController() {
            SimpleAction customAction = new SimpleAction(this, "CustomAction", PredefinedCategory.View);
            customAction.Execute += CustomAction_Execute;
        }
        private void CustomAction_Execute(object sender, SimpleActionExecuteEventArgs e) {
            AuditTrailService auditTrailService = ((EFCoreObjectSpace)ObjectSpace).GetAuditTrailService();
            auditTrailService.Enabled = false;
            // non-tracked actions or changes
            auditTrailService.Enabled = true;
        }
    }
    

    Note

    • The AuditTrailService.SaveCustomData method ignores the AuditTrailService.Enabled property. You can use this method when the property is set to false.
    • If you use one Object Space in multiple places simultaneously, the Audit Trail Module does not track changes throughout the application when AuditTrailService.Enabled is set to false.