Audit.DynamicProxy 30.0.1

dotnet add package Audit.DynamicProxy --version 30.0.1
                    
NuGet\Install-Package Audit.DynamicProxy -Version 30.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Audit.DynamicProxy" Version="30.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Audit.DynamicProxy" Version="30.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Audit.DynamicProxy" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Audit.DynamicProxy --version 30.0.1
                    
#r "nuget: Audit.DynamicProxy, 30.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Audit.DynamicProxy&version=30.0.1
                    
Install Audit.DynamicProxy as a Cake Addin
#tool nuget:?package=Audit.DynamicProxy&version=30.0.1
                    
Install Audit.DynamicProxy as a Cake Tool

Audit.DynamicProxy

Dynamic Proxy Extension for Audit.NET library.

Generate Audit Logs by intercepting operations on virtually any class.

Audit.DynamicProxy provides the infrastructure to create audit logs for a class without changing its code. It relies on Castle DynamicProxy library to intercept and record the operation calls (methods and properties) including caller info and arguments.

Install

NuGet Package

To install the package run the following command on the Package Manager Console:

PM> Install-Package Audit.DynamicProxy

NuGet Status NuGet Count

Usage

To enable the audit log for an instance of a class, create a proxy for the class by calling the AuditProxy.Create<>() method.

This will return a proxied audit-enabled instance that you should use instead of the real instance. Each operation on the proxy (access to a property or method call) will generate an Audit Event.

Suppose you have a MyRepository instance that you want to audit, like this:

public class MyDataAccess
{
    IMyRepository _repository = new MyRepository(); // <- Audit this object

    public async Task<int> InsertUserAsync(string userName)
    {
        return await _repository.InsertUserAsync(userName);
    }
    // ...
}

To enable the audit on the _repository object, intercept its assignation by calling AuditProxy.Create<>():

public class MyDataAccess
{
    IMyRepository _repository = AuditProxy.Create<IMyRepository>(new MyRepository()); // Audited!

    public async Task<int> InsertUserAsync(string userName)
    {
        return await _repository.InsertUserAsync(userName);
    }
    // ...
}

You can also intercept conditionally, for example to avoid auditing when a debugger is attached:

public class MyDataAccess
{
    IMyRepository _repository = new MyRepository();

    public MyDataAccess()
    {
        if (!Debugger.IsAttached)
        {
            // Audit only when no debugger is attached
            _repository = AuditProxy.Create<IMyRepository>(_repository);
        }
    }
}

Creating proxies

The AuditProxy.Create<>() method returns an auditable proxy object that inherits from the proxied class/implements proxied interface and forwards calls to the real object.

This is the method signature:

T AuditProxy.Create<T>(T instance, InterceptionSettings settings = null)

Give special attention to the generic type argument T, it can be:

  • An interface: Will generate an interface proxy to log all the interface member calls. (Recommended)
  • A class type: Will generate a class proxy to log virtual member calls. Non-virtual methods can't be automatically audited.

When using an interface proxy, the interception is limited to the members of the interface. And when using a class proxy, the interception is limited to its virtual members.

The instance argument is an instance of the object to be audited.

The settings argument allows you to change the default settings. See settings section for more information.

Settings

The InterceptionSettings class include the following settings:

  • EventType: A string that identifies the event type. Default is "{class}.{method}". Can contain the following placeholders:
    • {class}: Replaced by the class name
    • {method}: Replaced by the method name
  • IgnoreProperties: A boolean indicating whether the audit should ignore the property getters and setters. If true, the property accesses will not be logged. Default is false
  • IgnoreEvents: A boolean indicating whether the audit should ignore the event attach and detach operations. If true, the event accesses will not be logged. Default is false
  • MethodFilter: A function that takes a MethodInfo and returns a boolean indicating whether the method should be taken into account for the logging. Use this setting to have fine grained control over the methods that should be audited. By default all methods are included.
  • AuditDataProvider: Allows to set a specific audit data provider for this instance. By default the globally configured data provider is used. See Audit.NET Data Providers section for more information.

AuditIgnore Attribute

You can exclude specific members, arguments or return values from the audit, by decorating them with the AuditIgnore attribute. For example:

public class MyRepository : IMyRepository
{
    //Ignore a method (no events will be generated for this method)
    [AuditIgnore] 
    public User GetUser(string userName)
    {
       ...
    }

    //Ignore an argument (argument value will not be included in the output)
    public User FindUser(int type, [AuditIgnore] Filter filter)
    {
        ...
    }

    //Exclude the return value (result will not be included in the output)
    [return:AuditIgnore] 
    public List<User> SearchUsers(string text)
    {
        ...
    }
}

Customization

You can access the current audit scope from an audited member by getting the static AuditProxy.CurrentScope property.

The static property AuditProxy.CurrentScope returns the scope for the current running thread and should be accessed from the same thread as the executing audited operation. Calling this from a different thread will lead to an unexpected result. On async methods, you should only access this propery before any await ocurrence.

For example:

public class MyRepository : IMyRepository
{
    public async Task<int> InsertUserAsync(string userName)
    {
        var auditScope = AuditProxy.CurrentScope;   // Get the current scope
        auditScope.SetCustomField("TestField", Guid.NewGuid()); // Set a custom field
        
        //... existing code to insert user ...

        if (pleaseDoNotLog)
        {
            auditScope.Discard(); // Discard the event
        }

        return await _repository.InsertUserAsync(userName);
    }
}

Output

Audit.DynamicProxy output includes:

  • Execution time and duration (async-aware)
  • Environment information such as user, machine, domain and locale.
  • Method parameters (input and output)
  • Return object
  • Exception details
  • Comments and Custom Fields provided

With this information you can know who did the operation, and also measure performance, observe exceptions thrown and get statistics about usage of your classes.

Async calls are logged when the asynchronous call ends; as a continuation task, so the Audit Event includes the actual duration and result.

Output Details

The following table describes the Audit.DynamicProxy output fields:

AuditInterceptEvent

Describes an operation call event

Field Name Type Description
ClassName string Name of class where the operation is defined
MethodName string Name of the audited method
IsAsync boolean A boolean indicating whether the audited method is async
AsyncStatus string If the method is async, this will contain the final Task status (Canceled, Faulted, RanToCompletion)
InstanceQualifiedName string Full qualified name of the class
MethodSignature string The complete method signature
PropertyName string Name of the property modified (if any)
EventName string Name of the event modified (if any)
Arguments argument array The operation arguments (input and output parameters)
Success boolean Indicates if the operation completed succesfully
Exception string The exception details when an exception is thrown
Result argument object The result of the operation

AuditInterceptArgument

Describes an operation argument

Field Name Type Description
Index string Argument index
Name string Argument name
Type string Argument type
Value object Input argument value
OutputValue object Output argument value (Only for ref or out parameters)

Output Samples

Successful async method call:
{
  "EventType": "MyRepository.InsertUserAsync",
  "Environment": {
    "UserName": "Federico",
    "MachineName": "HP",
    "DomainName": "HP",
    "CallingMethodName": "Audit.DynamicProxy.AuditInterceptor.Intercept()",
    "AssemblyName": "Audit.DynamicProxy, Version=4.5.2.0, Culture=neutral, PublicKeyToken=null",
    "Culture": "en-GB"
  },
  "StartDate": "2016-09-30T12:00:35.7073819-05:00",
  "EndDate": "2016-09-30T12:00:36.7168197-05:00",
  "Duration": 1009,
  "InterceptEvent": {
    "ClassName": "MyRepository",
    "MethodName": "InsertUserAsync",
    "IsAsync": true,
    "AsyncStatus": "RanToCompletion",
    "InstanceQualifiedName": "Audit.DynamicProxy.UnitTest.MyRepository, Audit.DynamicProxy.UnitTest, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null",
    "MethodSignature": "System.Threading.Tasks.Task`1[System.Int32] InsertUserAsync(System.String)",
    "Arguments": [
      {
        "Index": 0,
        "Name": "userName",
        "Type": "String",
        "Value": "thepirat000"
      }
    ],
    "Success": true,
    "Result": {
      "Type": "Task<Int32>",
      "Value": 142857
    }
  }
}
Failed async method call:
{
  "EventType": "MyRepository.InsertUserAsync",
  "Environment": {
    "UserName": "Federico",
    "MachineName": "HP",
    "DomainName": "HP",
    "CallingMethodName": "Audit.DynamicProxy.AuditInterceptor.Intercept()",
    "AssemblyName": "Audit.DynamicProxy, Version=4.5.2.0, Culture=neutral, PublicKeyToken=null",
    "Exception": "COMException: Exception from HRESULT: 0xE0434352",
    "Culture": "en-GB"
  },
  "StartDate": "2016-09-30T12:18:34.5093824-05:00",
  "EndDate": "2016-09-30T12:18:35.5388113-05:00",
  "Duration": 1029,
  "InterceptEvent": {
    "ClassName": "MyRepository",
    "MethodName": "InsertUserAsync",
    "IsAsync": true,
    "AsyncStatus": "Faulted",
    "InstanceQualifiedName": "Audit.DynamicProxy.UnitTest.MyRepository, Audit.DynamicProxy.UnitTest, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null",
    "MethodSignature": "System.Threading.Tasks.Task`1[System.Int32] InsertUserAsync(System.String)",
    "Arguments": [
      {
        "Index": 0,
        "Name": "userName",
        "Type": "String",
        "Value": null
      }
    ],
    "Success": false,
    "Exception": "(ArgumentNullException) UserName cannot be null",
    "Result": null
  }
}

ZZZ Projects - Sponsorship

Entity Framework Extensions and Dapper Plus are major sponsors and are proud to contribute to the development of Audit.NET

Combine the power of auditing with the speed of Bulk Operations to get the best of both worlds — audit and performance.

Entity Framework Extensions - Sponsor

Dapper Plus - Sponsor

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
30.0.1 176 5/29/2025
30.0.0 149 5/27/2025
29.0.1 417 5/8/2025
29.0.0 154 5/6/2025
28.0.0 147 5/5/2025
27.5.3 195 4/23/2025
27.5.2 347 4/9/2025
27.5.1 242 4/4/2025
27.5.0 454 3/5/2025
27.4.1 206 2/9/2025
27.4.0 223 1/29/2025
27.3.3 132 1/21/2025
27.3.2 277 12/11/2024
27.3.1 102 12/10/2024
27.3.0 124 12/8/2024
27.2.0 165 11/23/2024
27.1.1 169 10/28/2024
27.1.0 112 10/24/2024
27.0.3 475 9/25/2024
27.0.2 127 9/19/2024
27.0.1 617 9/4/2024
27.0.0 115 9/3/2024
26.0.1 228 8/22/2024
26.0.0 156 7/19/2024
25.0.7 167 7/4/2024
25.0.6 153 6/24/2024
25.0.5 130 6/18/2024
25.0.4 584 3/24/2024
25.0.3 220 3/13/2024
25.0.2 147 3/12/2024
25.0.1 183 2/28/2024
25.0.0 183 2/16/2024
24.0.1 183 2/12/2024
24.0.0 133 2/12/2024
23.0.0 697 12/14/2023
22.1.0 190 12/9/2023
22.0.2 210 12/1/2023
22.0.1 249 11/16/2023
22.0.0 156 11/14/2023
21.1.0 4,034 10/9/2023
21.0.4 8,717 9/15/2023
21.0.3 3,034 7/9/2023
21.0.2 233 7/6/2023
21.0.1 625 5/27/2023
21.0.0 7,591 4/15/2023
20.2.4 1,356 3/27/2023
20.2.3 418 3/17/2023
20.2.2 349 3/14/2023
20.2.1 358 3/11/2023
20.2.0 378 3/7/2023
20.1.6 829 2/23/2023
20.1.5 3,186 2/9/2023
20.1.4 25,804 1/28/2023
20.1.3 432 12/21/2022
20.1.2 459 12/14/2022
20.1.1 477 12/12/2022
20.1.0 518 12/4/2022
20.0.4 461 11/30/2022
20.0.3 832 10/28/2022
20.0.2 576 10/26/2022
20.0.1 613 10/21/2022
20.0.0 692 10/1/2022
19.4.1 706 9/10/2022
19.4.0 634 9/2/2022
19.3.0 631 8/23/2022
19.2.2 671 8/11/2022
19.2.1 684 8/6/2022
19.2.0 773 7/24/2022
19.1.4 1,246 5/23/2022
19.1.3 629 5/22/2022
19.1.2 639 5/18/2022
19.1.1 790 4/28/2022
19.1.0 754 4/10/2022
19.0.7 811 3/13/2022
19.0.6 694 3/7/2022
19.0.5 767 1/28/2022
19.0.4 688 1/23/2022
19.0.3 747 12/14/2021
19.0.2 555 12/11/2021
19.0.1 990 11/20/2021
19.0.0 629 11/11/2021
19.0.0-rc.net60.2 222 9/26/2021
19.0.0-rc.net60.1 260 9/16/2021
18.1.6 1,080 9/26/2021
18.1.5 659 9/7/2021
18.1.4 582 9/6/2021
18.1.3 600 8/19/2021
18.1.2 700 8/8/2021
18.1.1 612 8/5/2021
18.1.0 655 8/1/2021
18.0.1 629 7/30/2021
18.0.0 649 7/26/2021
17.0.8 687 7/7/2021
17.0.7 1,847 6/16/2021
17.0.6 650 6/5/2021
17.0.5 685 5/28/2021
17.0.4 698 5/4/2021
17.0.3 653 5/1/2021
17.0.2 618 4/22/2021
17.0.1 647 4/18/2021
17.0.0 697 3/26/2021
16.5.6 688 3/25/2021
16.5.5 671 3/23/2021
16.5.4 679 3/9/2021
16.5.3 626 2/26/2021
16.5.2 636 2/23/2021
16.5.1 692 2/21/2021
16.5.0 611 2/17/2021
16.4.5 626 2/15/2021
16.4.4 597 2/5/2021
16.4.3 637 1/27/2021
16.4.2 707 1/22/2021
16.4.1 691 1/21/2021
16.4.0 693 1/11/2021
16.3.3 701 1/8/2021
16.3.2 711 1/3/2021
16.3.1 670 12/31/2020
16.3.0 619 12/30/2020
16.2.1 655 12/27/2020
16.2.0 911 10/13/2020
16.1.5 860 10/4/2020
16.1.4 1,055 9/17/2020
16.1.3 901 9/13/2020
16.1.2 755 9/9/2020
16.1.1 818 9/3/2020
16.1.0 789 8/19/2020
16.0.3 792 8/15/2020
16.0.2 808 8/9/2020
16.0.1 830 8/8/2020
16.0.0 718 8/7/2020
15.3.0 2,286 7/23/2020
15.2.3 796 7/14/2020
15.2.2 847 5/19/2020
15.2.1 829 5/12/2020
15.2.0 1,374 5/9/2020
15.1.1 853 5/4/2020
15.1.0 1,644 4/13/2020
15.0.5 3,109 3/18/2020
15.0.4 920 2/28/2020
15.0.3 820 2/26/2020
15.0.2 907 1/20/2020
15.0.1 929 1/10/2020
15.0.0 822 12/17/2019
14.9.1 881 11/30/2019
14.9.0 867 11/29/2019
14.8.1 886 11/26/2019
14.8.0 822 11/20/2019
14.7.0 863 10/9/2019
14.6.6 836 10/8/2019
14.6.5 849 9/27/2019
14.6.4 849 9/21/2019
14.6.3 987 8/12/2019
14.6.2 921 8/3/2019
14.6.1 815 8/3/2019
14.6.0 901 7/26/2019
14.5.7 910 7/18/2019
14.5.6 1,290 7/10/2019
14.5.5 889 7/1/2019
14.5.4 852 6/17/2019
14.5.3 925 6/5/2019
14.5.2 956 5/30/2019
14.5.1 935 5/28/2019
14.5.0 916 5/24/2019
14.4.0 1,616 5/22/2019
14.3.4 1,190 5/14/2019
14.3.3 913 5/9/2019
14.3.2 957 4/30/2019
14.3.1 953 4/27/2019
14.3.0 936 4/24/2019
14.2.3 937 4/17/2019
14.2.2 971 4/10/2019
14.2.1 990 4/5/2019
14.2.0 1,012 3/16/2019
14.1.1 956 3/8/2019
14.1.0 1,247 2/11/2019
14.0.4 2,480 1/31/2019
14.0.3 1,103 1/22/2019
14.0.2 1,031 12/15/2018
14.0.1 1,070 11/29/2018
14.0.0 1,120 11/19/2018
13.3.0 1,105 11/16/2018
13.2.2 1,108 11/15/2018
13.2.1 1,114 11/13/2018
13.2.0 1,173 10/31/2018
13.1.5 1,140 10/31/2018
13.1.4 1,129 10/25/2018
13.1.3 1,427 10/18/2018
13.1.2 1,256 9/12/2018
13.1.1 1,221 9/11/2018
13.1.0 1,189 9/11/2018
13.0.0 1,199 8/29/2018
12.3.6 1,233 8/29/2018
12.3.5 1,209 8/22/2018
12.3.4 1,268 8/21/2018
12.3.3 25,939 8/21/2018
12.3.2 1,197 8/20/2018
12.3.1 1,247 8/20/2018
12.3.0 1,239 8/20/2018
12.2.2 1,284 8/15/2018
12.2.1 1,273 8/9/2018
12.2.0 1,280 8/8/2018
12.1.11 1,247 7/30/2018
12.1.10 8,275 7/20/2018
12.1.9 1,430 7/10/2018
12.1.8 1,301 7/2/2018
12.1.7 1,539 6/7/2018
12.1.6 1,334 6/4/2018
12.1.5 1,409 6/2/2018
12.1.4 1,327 5/25/2018
12.1.3 1,638 5/16/2018
12.1.2 1,385 5/15/2018
12.1.1 1,512 5/14/2018
12.1.0 1,293 5/9/2018
12.0.7 1,572 5/5/2018
12.0.6 1,554 5/4/2018
12.0.5 1,545 5/3/2018
12.0.4 1,543 4/30/2018
12.0.3 1,319 4/30/2018
12.0.2 1,473 4/27/2018
12.0.1 1,287 4/25/2018
12.0.0 1,257 4/22/2018
11.2.0 1,530 4/11/2018
11.1.0 1,466 4/8/2018
11.0.8 1,499 3/26/2018
11.0.7 1,465 3/20/2018
11.0.6 1,418 3/7/2018
11.0.5 1,360 2/22/2018
11.0.4 1,472 2/14/2018
11.0.3 1,530 2/12/2018
11.0.2 1,336 2/9/2018
11.0.1 1,494 1/29/2018
11.0.0 1,904 1/15/2018
10.0.3 1,401 12/29/2017
10.0.2 1,493 12/26/2017
10.0.1 1,548 12/18/2017
10.0.0 1,343 12/18/2017
9.3.0 1,541 12/17/2017
9.2.0 1,531 12/17/2017
9.1.3 1,435 12/5/2017
9.1.2 1,437 11/27/2017
9.1.1 1,389 11/21/2017
9.1.0 1,380 11/21/2017
9.0.1 1,376 11/11/2017
9.0.0 1,417 11/10/2017
8.7.0 1,418 11/9/2017
8.6.0 1,389 11/9/2017
8.5.0 1,408 10/3/2017
8.4.0 1,409 10/3/2017
8.3.1 1,876 9/8/2017
8.3.0 1,450 9/8/2017
8.2.0 1,478 9/4/2017
8.1.0 1,478 8/22/2017
8.0.0 1,667 8/19/2017
7.1.3 1,450 8/14/2017
7.1.2 1,390 8/2/2017
7.1.1 1,382 7/26/2017
7.1.0 1,451 7/5/2017
7.0.9 1,471 6/28/2017
7.0.8 1,509 6/19/2017
7.0.6 1,526 4/7/2017
7.0.5 1,480 3/21/2017
7.0.4 1,449 3/21/2017
7.0.3 1,471 3/20/2017
7.0.2 1,449 3/13/2017
7.0.0 1,459 3/1/2017
6.2.0 1,553 2/25/2017
6.1.0 1,476 2/14/2017
6.0.0 1,604 2/9/2017
5.3.0 1,499 2/5/2017
5.2.0 1,456 1/26/2017
5.1.0 1,454 1/19/2017
5.0.0 1,454 1/7/2017
4.11.0 1,435 1/5/2017
4.10.0 1,457 12/31/2016
4.9.0 1,406 12/26/2016
4.8.0 1,415 12/17/2016
4.7.0 1,460 12/8/2016
4.6.5 1,481 12/4/2016
4.6.4 1,438 11/25/2016
4.6.2 1,444 11/18/2016
4.6.1 1,420 11/15/2016
4.6.0 1,436 11/11/2016
4.5.9 1,627 11/2/2016
4.5.8 1,491 11/2/2016
4.5.7 1,425 10/26/2016
4.5.6 1,391 10/6/2016
4.5.5 1,427 10/3/2016
4.5.4 1,400 10/2/2016
4.5.3 1,434 9/30/2016
4.5.2 1,465 9/28/2016
4.5.1 1,420 9/28/2016
4.5.0 1,445 9/28/2016