Docs
Tenantry ProAPI reference

AuditOptions class

Namespace: Tenantry.Pro.EfCore · Package: Tenantry.Pro.EfCore · API reference

Options for the Tenantry.Pro audit-logging feature. Configure via pro.AddAuditLogging(opts => { ... }).

public sealed class AuditOptions

Properties

OnStoreFailure

What happens when the store fails to write the entries of changes that are already saved, with AuditTiming.AfterCommit: the failure is logged (AuditStoreFailureBehavior.Log, the default) or thrown as an AuditStoreException (AuditStoreFailureBehavior.Throw). With AuditTiming.InTransaction the store's failure is always thrown, as it is.

public AuditStoreFailureBehavior OnStoreFailure { get; set; }

Value: AuditStoreFailureBehavior

ShouldAudit

Decides, for each entity a save inserts, updates or deletes, whether to record it: return false to leave it out. Called before its values are read, after the exclusions of AuditOptions.Exclude<TEntity>. null (the default) records every entity not excluded.

public Func<EntityEntry, bool>? ShouldAudit { get; set; }

Value: Func<EntityEntry, bool>

An owned entity is an entity of its own here, asked about on its own (entry.Metadata.IsOwned()): leaving out its owner does not leave it out. AuditOptions.Exclude<TEntity> leaves out what an excluded type owns.

opts.ShouldAudit = entry => entry.Metadata.GetTableName() != "Sessions";

Timing

When a save's entries reach IAuditStore: once the changes are committed (AuditTiming.AfterCommit, the default), or inside the transaction they were saved in (AuditTiming.InTransaction).

public AuditTiming Timing { get; set; }

Value: AuditTiming

Methods

ExcludeProperty<TEntity>(Expression<Func<TEntity, object?>>)

Leaves a property out of every entry of TEntity, and of types derived from it: its value is not copied, and it is not in AuditEntry.OldValues, AuditEntry.NewValues or AuditEntry.ChangedProperties. A key property still makes up AuditEntry.PrimaryKey. An update that changes only excluded properties is not recorded. Naming the navigation to an owned type (OwnsOne, OwnsMany) leaves out the entities owned through it, and naming a complex property (ComplexProperty, ComplexCollection) leaves out its values.

public AuditOptions ExcludeProperty<TEntity>(Expression<Func<TEntity, object?>> property)

Type parameters:

  • TEntity: The entity type, complex type, base type or interface that has the property.

Parameters:

  • property Expression<Func<TEntity, object>>: The property, as x => x.PasswordHash, or a navigation to an owned type, or a complex property. For one property of an owned or complex type, name it on that type.

Returns: AuditOptions: The same options, for chaining.

Exceptions:

  • ArgumentException: property is not a member of TEntity itself (a nested member, a method call).
opts.ExcludeProperty<User>(user => user.PasswordHash);

Exclude<TEntity>()

Leaves TEntity out of the audit: every entity of that type, of a type derived from it (or implementing it, for an interface), and the entities they own (OwnsOne, OwnsMany).

public AuditOptions Exclude<TEntity>() where TEntity : class

Type parameters:

  • TEntity: The entity type, base type or interface to exclude.

Returns: AuditOptions: The same options, for chaining.

opts.Exclude<OutboxMessage>();

On this page