This page documents Audit.DynamicProxy, a library that enables non-invasive auditing of class instances without modifying their source code. It uses Castle DynamicProxy to intercept method calls and property accesses, automatically generating audit events for operations performed on proxied instances.
For other application integration patterns, see:
Key Characteristics:
Sources: src/Audit.DynamicProxy/README.md1-10
Diagram: Dynamic Proxy Architecture
The proxy pattern creates a wrapper object that implements the same interface (or inherits from the same class) as the target, intercepting all method calls before forwarding them to the real instance.
Sources: src/Audit.DynamicProxy/README.md23-91 src/Audit.DynamicProxy/Audit.DynamicProxy.csproj1-54
The entry point for creating auditable proxies is the static factory method:
T AuditProxy.Create<T>(T instance, InterceptionSettings settings = null)
Type Parameter T Constraints:
| Proxy Type | Description | Limitations |
|---|---|---|
| Interface | Generates interface proxy | Only interface members are intercepted (Recommended) |
| Class | Generates class proxy | Only virtual members are intercepted |
Sources: src/Audit.DynamicProxy/README.md74-91
Diagram: Interface Proxy Implementation
Usage Pattern:
The proxied instance can be used as a drop-in replacement for the real instance, with all interface method calls automatically audited.
Sources: src/Audit.DynamicProxy/README.md29-55
For class proxies, only virtual members can be intercepted:
Sources: src/Audit.DynamicProxy/README.md84-86
Sources: src/Audit.DynamicProxy/README.md57-72
The InterceptionSettings class provides fine-grained control over proxy behavior:
Diagram: InterceptionSettings Class Structure
Sources: src/Audit.DynamicProxy/README.md92-105
| Property | Type | Default | Description |
|---|---|---|---|
| EventType | string | "{class}.{method}" | Event type identifier with placeholders |
| IgnoreProperties | bool | false | Skip logging property getters/setters |
| IgnoreEvents | bool | false | Skip logging event attach/detach |
| MethodFilter | Func<MethodInfo, bool> | null | Fine-grained method inclusion filter |
| AuditDataProvider | AuditDataProvider | Global | Instance-specific data provider |
EventType Placeholders:
{class}: Replaced with class name{method}: Replaced with method nameSources: src/Audit.DynamicProxy/README.md96-104
Basic Configuration:
Advanced Filtering:
Sources: src/Audit.DynamicProxy/README.md92-105
The AuditIgnore attribute provides declarative exclusion of members, arguments, or return values from audit logging:
Diagram: AuditIgnore Attribute Application
Sources: src/Audit.DynamicProxy/README.md106-134
Method Exclusion:
Argument Exclusion:
Return Value Exclusion:
Sources: src/Audit.DynamicProxy/README.md109-133
The static property AuditProxy.CurrentScope provides access to the AuditScope associated with the currently executing proxied method:
Diagram: Current Scope Access Flow
Sources: src/Audit.DynamicProxy/README.md136-162
Important: AuditProxy.CurrentScope is thread-static and must be accessed from the same thread as the executing operation:
await in async methodsawait (continuation may run on different thread)Example:
Sources: src/Audit.DynamicProxy/README.md136-162
Sources: src/Audit.DynamicProxy/README.md143-161
Diagram: Output Event Object Model
Sources: src/Audit.DynamicProxy/README.md180-211
| Field | Type | Description |
|---|---|---|
| ClassName | string | Name of the class containing the method |
| MethodName | string | Name of the audited method |
| IsAsync | boolean | Whether the method is async |
| AsyncStatus | string | Final task status: Canceled, Faulted, RanToCompletion |
| InstanceQualifiedName | string | Assembly-qualified type name |
| MethodSignature | string | Complete method signature |
| PropertyName | string | Property name (for property accessors) |
| EventName | string | Event name (for event handlers) |
| Arguments | array | Input and output parameter values |
| Success | boolean | Whether operation completed successfully |
| Exception | string | Exception details if thrown |
| Result | object | Return value of the method |
Sources: src/Audit.DynamicProxy/README.md186-199
| Field | Type | Description |
|---|---|---|
| Index | int | Argument index in parameter list |
| Name | string | Parameter name |
| Type | string | Parameter type name |
| Value | object | Input argument value |
| OutputValue | object | Output value for ref/out parameters |
Sources: src/Audit.DynamicProxy/README.md201-211
Sources: src/Audit.DynamicProxy/README.md215-251
Sources: src/Audit.DynamicProxy/README.md253-290
Diagram: Repository Pattern with Audit Proxy
Implementation:
Sources: src/Audit.DynamicProxy/README.md29-55
When using dependency injection, create the proxy in the service registration:
This pattern ensures all injected instances are automatically audited without modifying consuming code.
Sources: src/Audit.WebApi/README.md504-508
Diagram: Multi-Layer Auditing Pattern
This pattern can be combined with other Audit.NET extensions:
Sources: src/Audit.WebApi/README.md504-508
Package Name: Audit.DynamicProxy
Dependencies:
Audit.NET (core library)Castle.Core version 5.1.1Target Frameworks:
Sources: src/Audit.DynamicProxy/Audit.DynamicProxy.csproj1-54
PM> Install-Package Audit.DynamicProxy
Sources: src/Audit.DynamicProxy/README.md14-18
| Class | Location | Purpose |
|---|---|---|
| AuditProxy | Audit.DynamicProxy | Static factory for creating proxied instances |
| AuditInterceptor | Audit.DynamicProxy | Implements Castle IInterceptor for method interception |
| InterceptionSettings | Audit.DynamicProxy | Configuration for proxy behavior |
| AuditInterceptEvent | Audit.DynamicProxy | Event data model for intercepted operations |
| AuditInterceptArgument | Audit.DynamicProxy | Represents method arguments in audit events |
Sources: src/Audit.DynamicProxy/README.md1-301 src/Audit.DynamicProxy/Audit.DynamicProxy.csproj1-54
Refresh this wiki