Skip to main content

Disable the Audit Trail Module

  • 2 minutes to read

This topic demonstrates two options you can use to disable the Audit Trail Module in your application:

In a Configuration File

Add the EnableAuditTrail key with the False value to an application’s configuration file, as shown below:

<appSettings>
    <!-- ... -->
    <add key="EnableAuditTrail" value ="False"/>
    <!-- ... -->
</appSettings>

In Application Code

In .NET 6+ Applications

In .NET 6+ applications, the Audit Trail Module runs as a service. You can use the service provider’s GetRequiredService method to access the audit trail options:

File: MySolution.Blazor.Server/Startup.cs, MySolution.Win/Startup.cs

using DevExpress.ExpressApp.AuditTrail;
using DevExpress.ExpressApp.Security;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

public class Startup {
    // ...
    public void ConfigureServices(IServiceCollection services) {
        // ...
        services.AddScoped<CircuitHandler, CircuitHandlerProxy>();
        services.AddXaf(Configuration, builder => {
            builder.Security
                .UseIntegratedMode(options => {
                    options.Events.OnLogon += context => {
                        string userName = ((ApplicationUser)context.User).UserName;
                        if (userName == "User") {
                            var auditOptions = context.ServiceProvider.GetRequiredService<IOptionsSnapshot<AuditTrailOptions>>().Value;
                            auditOptions.Enabled = false;
                        }
                    };
                    //...
                })
            // ...
        }
        // ...
    }
    // ...
}

The code snippet above handles the SecurityEvents.OnLogon event to disable audit for a certain user when they log in to the application. Note that the AuditTrailOptions type is wrapped into IOptionsSnapshot, which is then passed as the GetRequiredService method’s type parameter. This is done to disable the Audit Trail module in the current scope only. For more information, refer to the following topic: Use IOptionsSnapshot to read updated data.

In .NET Framework Applications

Access the Audit Trail Module and specify its AuditTrailModule.Enabled property in the XafApplication.LoggedOn event handler, as shown below:

using DevExpress.ExpressApp.Win;
using DevExpress.ExpressApp.AuditTrail;
// ...
public class MySolutionWinApplication : WinApplication {
    // ...
    protected override void OnLoggedOn(LogonEventArgs args) {
        base.OnLoggedOn(args);
        AuditTrailModule auditTrailModule = this.Modules.FindModule<AuditTrailModule>();
        if(Security.UserName == "John") {
            auditTrailModule.Enabled = false;
        }
    }
}