Audit.WCF 28.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Audit.WCF --version 28.0.0
                    
NuGet\Install-Package Audit.WCF -Version 28.0.0
                    
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.WCF" Version="28.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Audit.WCF" Version="28.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Audit.WCF" />
                    
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.WCF --version 28.0.0
                    
#r "nuget: Audit.WCF, 28.0.0"
                    
#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.
#:package Audit.WCF@28.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Audit.WCF&version=28.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Audit.WCF&version=28.0.0
                    
Install as a Cake Tool

Audit.WCF

WCF Audit Extension for Audit.NET library.

Generate Audit Logs for Windows Communication Foundation (WCF) service calls.

Audit.Wcf provides the server-side infrastructure to log interactions with WCF services. It records detailed information of the service method calls.

If you are looking for client-side audit, please check the Audit.WCF.Client library.

Install

NuGet Package

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

PM> Install-Package Audit.Wcf

NuGet Status NuGet Count

Usage

Decorate your WCF service class or methods with the Audit.WCF.AuditBehavior attribute.

For example:

[AuditBehavior(EventType = "{contract}.{operation}")]
public class OrderService : IOrderService
{
  public async Task<GetOrderResponse> GetOrder(GetOrderRequest request)
  {
    ...
  }
}

You can also decorate the specific methods you want to audit, for example:

public class OrderService : IOrderService
{
  [AuditBehavior]
  public async Task<GetOrderResponse> GetOrder(GetOrderRequest request)
  {
    ...
  }
}

If you can't (or do not want) to change the service code, you can also enable the audit mechanism by adding the AuditBehavior extension to your service host configuration file.

For example:

<configuration>
  <system.serviceModel>
    ...
    <extensions>
      <behaviorExtensions>
	      <add name="auditBehavior" type="Audit.WCF.AuditBehavior, Audit.WCF" />
      </behaviorExtensions>
    </extensions>

    <behaviors>
      <serviceBehaviors>
	      <behavior>
	        <auditBehavior eventType="{contract}.{operation}" />
	      </behavior>
      </serviceBehaviors>
    </behaviors>
    ...
  </system.serviceModel>
</configuration>

Configuration

The AuditBehavior attribute or extension can be configured with the following properties:

  • EventTypeName: A string that identifies the event type. Can contain the following placeholders:
    • {contract}: Replaced with the contract name (service interface name)
    • {operation}: Replaces with the operation name (service method name)
  • AuditDataProvider: Allows to set a specific audit data provider. By default the globally configured data provider is used. See Audit.NET Data Providers section for more information.
  • AuditScopeFactory: Allows to set a specific audit scope factory. By default the globally configured AuditScopeFactory is used.

To globally configure the output persistence mechanism, use the Audit.Core.Configuration class. For more details please see Event Output Configuration.

For example:

Audit.Core.Configuration.Setup()
	.UseFileLogProvider(config => config.Directory(@"C:\Logs"));

This should be done prior to the AuditScope creation, i.e. during application startup.

If you want to configure an Audit Data Provider per service instance, you can add a public instance property named AuditDataProvider to your service class and make it return the provider you want, for example:

[AuditBehavior]
public class OrderService : IOrderService
{
    public AuditDataProvider AuditDataProvider
    {
        get
        {
            return new Audit.Core.Providers.FileDataProvider()
            {
                DirectoryPath = @"C:\Logs"
            };
        }
    }
}

The library will automatically detect the property and use the given data provider for that service instance.

You can do the same with the AuditScopeFactory property to provide a custom IAuditScopeFactory instance.


## Output

`Audit.Wcf` output includes:

- Execution time and duration
- Environment information such as user, machine, domain and locale.
- Authenticated username (identity name)
- Client IP address
- Contract and Operation details
- Method parameters (in and out)
- Response object
- Faults and Exceptions details
- [Comments and Custom Fields](#custom-fields-and-comments) provided

With this information, you can not just know who did the operation, but also measure performance, observe exceptions thrown or get statistics about usage of your WCF service.

## Output details

The following table describes the `Audit.Wcf` output fields:

- ### [AuditWcfEvent](https://github.com/thepirat000/Audit.NET/blob/master/src/Audit.WCF/AuditWcfEvent.cs)

Describes an audited WCF event

| Field Name | Type | Description | 
| ------------ | ---------------- |  -------------- |
| ContractName | string | Name of the contract (service interface) |
| OperationName | string | Name of the operation (service method) |
| InstanceQualifiedName | string | Assembly qualified type name of the service instance |
| IsAsync | boolean | Indicates if the operation is asynchronous |
| MethodSignature | string | Signature of the audited method |
| Action | string | Action absolute address |
| ReplyAction | string |Reply action absolute address |
| IdentityName | string | Name of the current identity (username) |
| ClientAddress | string | Client address (IP) |
| HostAddress | string | Serice host address |
| Success | boolean | Indicates if the operation completed succesfully |
| Fault | [AuditWcfEventFault](#AuditWcfEventFault) | Fault details when the operation fails |
| Result | Object | The result object value |
| InputParameters | Array of [AuditWcfEventElement](#AuditWcfEventElement) | Input parameters object values |
| OutputParameters | Array of [AuditWcfEventElement](#AuditWcfEventElement) | Output parameters object values |

- ### [AuditWcfEventFault](https://github.com/thepirat000/Audit.NET/blob/master/src/Audit.WCF/AuditWcfEventFault.cs)

Describes a WCF fault/exception

| Field Name | Type | Description | 
| ------------ | ---------------- |  -------------- |
| FaultType | string | Fault type (Exception / Fault) |
| Exception | string | Exception details |
| FaultCode | string | The fault code |
| FaultAction | string | The fault action name |
| FaultReason | string | The fault reason |
| FaultDetails | [AuditWcfEventElement](#AuditWcfEventElement) | The detail object related to the fault |

- ### [AuditWcfEventElement](https://github.com/thepirat000/Audit.NET/blob/master/src/Audit.WCF/AuditWcfEventElement.cs)

Describes an element/object related to the WCF audit event.

| Field Name | Type | Description | 
| ------------ | ---------------- |  -------------- |
| Type | string | The object type name |
| Value | Object | The object value |

## Customization

You can access the `AuditScope` object for customization from the audited methods, by the static property `Audit.WCF.AuditBehavior.CurrentAuditScope`. 

For example:
```c#
using Audit.WCF;

[AuditBehavior]
public class OrderService : IOrderService
{
    public GetOrderResponse GetOrder(GetOrderRequest request)
    {
        AuditBehavior.CurrentAuditScope.Comment("some comment");
        AuditBehavior.CurrentAuditScope.SetCustomField("User", MySession.CurrentUser);
        ...
    }
}

See Audit.NET documentation about Custom Field and Comments for more information.

Output Sample

{
	"EventType": "IOrderService.GetOrder",
	"Environment": {
		"UserName": "Federico",
		"MachineName": "HP",
		"DomainName": "HP",
		"CallingMethodName": "WCF_IIS.IOrderService.GetData()",
		"AssemblyName": "WCF_IIS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
		"Exception": null,
		"Culture": "en-GB"
	},
	"StartDate": "2016-09-13T01:31:58.6843094-05:00",
	"EndDate": "2016-09-13T01:31:58.6858324-05:00",
	"Duration": 2,
	"WcfEvent": {
		"ContractName": "IOrderService",
		"OperationName": "GetOrder",
		"InstanceQualifiedName": "WCF_IIS.OrderService, WCF_IIS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
		"MethodSignature": "WCF_IIS.GetOrderResponse GetOrder(WCF_IIS.GetOrderRequest)",
		"Action": "http://tempuri.org/IOrderService/GetOrder",
		"ReplyAction": "http://tempuri.org/IOrderService/GetOrderResponse",
		"ClientAddress": "::1",
		"HostAddress": "http://localhost:8733/Design_Time_Addresses/WCF_IIS/OrderService/",
		"InputParameters": [{
			"Type": "GetOrderRequest",
			"Value": {
				"OrderId": 123
			}
		}],
		"Success": true,
		"Result": {
			"Type": "GetOrderResponse",
			"Value": {
				"Success": true,
				"Errors": null,
				"Order": {
					"OrderId": 123,
					"CustomerName": "customer",
					"Total": 10.0
				}
			}
		},
		"OutputParameters": []
	}
}

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 Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 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
31.0.1 201 8/28/2025
31.0.0 137 8/22/2025
30.1.3 169 8/19/2025
30.1.2 159 8/14/2025
30.1.1 150 8/13/2025
30.0.2 213 6/26/2025
30.0.1 180 5/29/2025
30.0.0 156 5/27/2025
29.0.1 167 5/8/2025
29.0.0 164 5/6/2025
28.0.0 162 5/5/2025
27.5.3 185 4/23/2025
27.5.2 211 4/9/2025
27.5.1 115 4/4/2025
27.5.0 271 3/5/2025
27.4.1 225 2/9/2025
27.4.0 127 1/29/2025
27.3.3 129 1/21/2025
27.3.2 189 12/11/2024
27.3.1 119 12/10/2024
27.3.0 126 12/8/2024
27.2.0 165 11/23/2024
27.1.1 120 10/28/2024
27.1.0 343 10/24/2024
27.0.3 140 9/25/2024
27.0.2 146 9/19/2024
27.0.1 142 9/4/2024
27.0.0 136 9/3/2024
26.0.1 375 8/22/2024
26.0.0 165 7/19/2024
25.0.7 171 7/4/2024
25.0.6 149 6/24/2024
25.0.5 142 6/18/2024
25.0.4 212 3/24/2024
25.0.3 234 3/13/2024
25.0.2 219 3/12/2024
25.0.1 243 2/28/2024
25.0.0 277 2/16/2024
24.0.1 311 2/12/2024
24.0.0 291 2/12/2024
23.0.0 559 12/14/2023
22.1.0 487 12/9/2023
22.0.2 489 12/1/2023
22.0.1 510 11/16/2023
22.0.0 497 11/14/2023
21.1.0 582 10/9/2023
21.0.4 598 9/15/2023
21.0.3 818 7/9/2023
21.0.2 742 7/6/2023
21.0.1 812 5/27/2023
21.0.0 854 4/15/2023
20.2.4 914 3/27/2023
20.2.3 856 3/17/2023
20.2.2 895 3/14/2023
20.2.1 882 3/11/2023
20.2.0 890 3/7/2023
20.1.6 904 2/23/2023
20.1.5 926 2/9/2023
20.1.4 945 1/28/2023
20.1.3 981 12/21/2022
20.1.2 1,028 12/14/2022
20.1.1 1,007 12/12/2022
20.1.0 992 12/4/2022
20.0.4 1,079 11/30/2022
20.0.3 1,126 10/28/2022
20.0.2 1,089 10/26/2022
20.0.1 1,121 10/21/2022
20.0.0 1,158 10/1/2022
19.4.1 1,196 9/10/2022
19.4.0 1,169 9/2/2022
19.3.0 1,144 8/23/2022
19.2.2 1,142 8/11/2022
19.2.1 1,185 8/6/2022
19.2.0 1,166 7/24/2022
19.1.4 1,432 5/23/2022
19.1.3 1,222 5/22/2022
19.1.2 1,293 5/18/2022
19.1.1 1,280 4/28/2022
19.1.0 1,210 4/10/2022
19.0.7 2,703 3/13/2022
19.0.6 1,267 3/7/2022
19.0.5 1,330 1/28/2022
19.0.4 1,278 1/23/2022
19.0.3 1,162 12/14/2021
19.0.2 1,150 12/11/2021
19.0.1 1,504 11/20/2021
19.0.0 1,214 11/11/2021
19.0.0-rc.net60.2 244 9/26/2021
19.0.0-rc.net60.1 306 9/16/2021
18.1.6 1,260 9/26/2021
18.1.5 2,486 9/7/2021
18.1.4 1,199 9/6/2021
18.1.3 1,211 8/19/2021
18.1.2 1,269 8/8/2021
18.1.1 1,271 8/5/2021
18.1.0 1,342 8/1/2021
18.0.1 1,270 7/30/2021
18.0.0 1,271 7/26/2021
17.0.8 1,255 7/7/2021
17.0.7 1,245 6/16/2021
17.0.6 1,211 6/5/2021
17.0.5 1,265 5/28/2021
17.0.4 1,331 5/4/2021
17.0.3 1,305 5/1/2021
17.0.2 1,245 4/22/2021
17.0.1 1,237 4/18/2021
17.0.0 1,258 3/26/2021
16.5.6 1,247 3/25/2021
16.5.5 1,217 3/23/2021
16.5.4 1,265 3/9/2021
16.5.3 1,287 2/26/2021
16.5.2 1,275 2/23/2021
16.5.1 1,262 2/21/2021
16.5.0 1,253 2/17/2021
16.4.5 1,287 2/15/2021
16.4.4 1,259 2/5/2021
16.4.3 1,218 1/27/2021
16.4.2 1,270 1/22/2021
16.4.1 1,249 1/21/2021
16.4.0 1,264 1/11/2021
16.3.3 1,278 1/8/2021
16.3.2 1,300 1/3/2021
16.3.1 1,333 12/31/2020
16.3.0 1,257 12/30/2020
16.2.1 1,307 12/27/2020
16.2.0 1,581 10/13/2020
16.1.5 1,405 10/4/2020
16.1.4 1,408 9/17/2020
16.1.3 1,421 9/13/2020
16.1.2 1,304 9/9/2020
16.1.1 1,344 9/3/2020
16.1.0 1,343 8/19/2020
16.0.3 1,371 8/15/2020
16.0.2 1,336 8/9/2020
16.0.1 1,430 8/8/2020
16.0.0 1,336 8/7/2020
15.3.0 2,241 7/23/2020
15.2.3 1,453 7/14/2020
15.2.2 1,448 5/19/2020
15.2.1 1,404 5/12/2020
15.2.0 1,416 5/9/2020
15.1.1 1,481 5/4/2020
15.1.0 1,506 4/13/2020
15.0.5 1,386 3/18/2020
15.0.4 1,412 2/28/2020
15.0.3 1,409 2/26/2020
15.0.2 1,493 1/20/2020
15.0.1 1,444 1/10/2020
15.0.0 1,471 12/17/2019
14.9.1 1,457 11/30/2019
14.9.0 1,408 11/29/2019
14.8.1 1,425 11/26/2019
14.8.0 1,440 11/20/2019
14.7.0 7,247 10/9/2019
14.6.6 1,379 10/8/2019
14.6.5 1,402 9/27/2019
14.6.4 1,479 9/21/2019
14.6.3 1,850 8/12/2019
14.6.2 1,496 8/3/2019
14.6.1 1,527 8/3/2019
14.6.0 1,535 7/26/2019
14.5.7 1,526 7/18/2019
14.5.6 1,486 7/10/2019
14.5.5 1,488 7/1/2019
14.5.4 1,552 6/17/2019
14.5.3 1,531 6/5/2019
14.5.2 1,504 5/30/2019
14.5.1 1,515 5/28/2019
14.5.0 1,639 5/24/2019
14.4.0 1,576 5/22/2019
14.3.4 1,530 5/14/2019
14.3.3 1,454 5/9/2019
14.3.2 1,684 4/30/2019
14.3.1 1,509 4/27/2019
14.3.0 1,568 4/24/2019
14.2.3 1,581 4/17/2019
14.2.2 1,535 4/10/2019
14.2.1 1,538 4/5/2019
14.2.0 1,569 3/16/2019
14.1.1 1,596 3/8/2019
14.1.0 1,681 2/11/2019
14.0.4 1,696 1/31/2019
14.0.3 1,625 1/22/2019
14.0.2 1,788 12/15/2018
14.0.1 1,713 11/29/2018
14.0.0 1,687 11/19/2018
13.3.0 1,761 11/16/2018
13.2.2 1,713 11/15/2018
13.2.1 1,630 11/13/2018
13.2.0 1,690 10/31/2018
13.1.5 1,641 10/31/2018
13.1.4 1,678 10/25/2018
13.1.3 1,717 10/18/2018
13.1.2 1,860 9/12/2018
13.1.1 1,777 9/11/2018
13.1.0 1,785 9/11/2018
13.0.0 1,778 8/29/2018
12.3.6 1,718 8/29/2018
12.3.5 1,801 8/22/2018
12.3.4 1,822 8/21/2018
12.3.3 26,547 8/21/2018
12.3.2 1,792 8/20/2018
12.3.1 1,819 8/20/2018
12.3.0 1,807 8/20/2018
12.2.2 1,828 8/15/2018
12.2.1 1,882 8/9/2018
12.2.0 1,891 8/8/2018
12.1.11 1,876 7/30/2018
12.1.10 1,952 7/20/2018
12.1.9 2,188 7/10/2018
12.1.8 3,515 7/2/2018
12.1.7 2,175 6/7/2018
12.1.6 1,982 6/4/2018
12.1.5 2,133 6/2/2018
12.1.4 2,001 5/25/2018
12.1.3 2,515 5/16/2018
12.1.2 2,020 5/15/2018
12.1.1 2,271 5/14/2018
12.1.0 2,187 5/9/2018
12.0.7 2,235 5/5/2018
12.0.6 1,973 5/4/2018
12.0.5 2,201 5/3/2018
12.0.4 2,242 4/30/2018
12.0.3 2,232 4/30/2018
12.0.2 2,225 4/27/2018
12.0.1 2,216 4/25/2018
12.0.0 1,995 4/22/2018
11.2.0 2,283 4/11/2018
11.1.0 2,022 4/8/2018
11.0.8 2,202 3/26/2018
11.0.7 1,961 3/20/2018
11.0.6 2,218 3/7/2018
11.0.5 2,274 2/22/2018
11.0.4 2,215 2/14/2018
11.0.3 2,185 2/12/2018
11.0.2 2,200 2/9/2018
11.0.1 2,030 1/29/2018
11.0.0 2,185 1/15/2018
10.0.3 2,187 12/29/2017
10.0.2 1,958 12/26/2017
10.0.1 2,207 12/18/2017
10.0.0 1,998 12/18/2017
9.3.0 2,184 12/17/2017
9.2.0 2,180 12/17/2017
9.1.3 2,098 12/5/2017
9.1.2 1,974 11/27/2017
9.1.1 2,048 11/21/2017
9.1.0 1,961 11/21/2017
9.0.1 1,938 11/11/2017
9.0.0 1,944 11/10/2017
8.7.0 1,973 11/9/2017
8.6.0 1,928 11/9/2017
8.5.0 1,959 10/3/2017
8.4.0 2,018 10/3/2017
8.3.1 2,627 9/8/2017
8.3.0 2,006 9/8/2017
8.2.0 1,985 9/4/2017
8.1.0 2,065 8/22/2017
8.0.0 2,231 8/19/2017
7.1.3 1,986 8/14/2017
7.1.2 1,985 8/2/2017
7.1.1 1,929 7/26/2017
7.1.0 1,989 7/5/2017
7.0.9 1,943 6/28/2017
7.0.8 2,064 6/19/2017
7.0.6 2,019 4/7/2017
7.0.5 1,945 3/21/2017
7.0.4 1,980 3/21/2017
7.0.3 1,970 3/20/2017
7.0.2 1,972 3/13/2017
7.0.0 2,052 3/1/2017
6.2.0 2,046 2/25/2017
6.1.0 2,061 2/14/2017
6.0.0 2,104 2/9/2017
5.3.0 2,006 2/5/2017
5.2.0 1,943 1/26/2017
5.1.0 1,982 1/19/2017
5.0.0 1,984 1/7/2017
4.11.0 2,056 1/5/2017
4.10.0 2,049 12/31/2016
4.9.0 1,964 12/26/2016
4.8.0 3,710 12/17/2016
4.7.0 2,084 12/8/2016
4.6.5 2,011 12/4/2016
4.6.4 1,996 11/25/2016
4.6.2 3,691 11/18/2016
4.6.1 2,056 11/15/2016
4.6.0 2,001 11/11/2016
4.5.9 3,915 11/2/2016
4.5.8 2,135 11/2/2016
4.5.7 3,825 10/26/2016
4.5.6 2,039 10/6/2016
4.5.5 2,041 10/3/2016
4.5.4 1,990 10/2/2016
4.5.3 2,013 9/30/2016
4.5.2 3,785 9/28/2016
4.5.1 3,705 9/28/2016
4.5.0 3,657 9/28/2016
4.4.0 3,913 9/23/2016
4.3.0 2,126 9/22/2016
4.2.0 2,280 9/19/2016
4.1.1 2,049 9/13/2016
4.1.0 2,027 9/13/2016