Audit.WCF 27.3.2

dotnet add package Audit.WCF --version 27.3.2                
NuGet\Install-Package Audit.WCF -Version 27.3.2                
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="27.3.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Audit.WCF --version 27.3.2                
#r "nuget: Audit.WCF, 27.3.2"                
#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.
// Install Audit.WCF as a Cake Addin
#addin nuget:?package=Audit.WCF&version=27.3.2

// Install Audit.WCF as a Cake Tool
#tool nuget:?package=Audit.WCF&version=27.3.2                

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": []
	}
}
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
27.3.2 93 12/11/2024
27.3.1 75 12/10/2024
27.3.0 83 12/8/2024
27.2.0 107 11/23/2024
27.1.1 88 10/28/2024
27.1.0 103 10/24/2024
27.0.3 107 9/25/2024
27.0.2 116 9/19/2024
27.0.1 113 9/4/2024
27.0.0 109 9/3/2024
26.0.1 140 8/22/2024
26.0.0 114 7/19/2024
25.0.7 145 7/4/2024
25.0.6 108 6/24/2024
25.0.5 113 6/18/2024
25.0.4 182 3/24/2024
25.0.3 208 3/13/2024
25.0.2 183 3/12/2024
25.0.1 211 2/28/2024
25.0.0 235 2/16/2024
24.0.1 285 2/12/2024
24.0.0 256 2/12/2024
23.0.0 526 12/14/2023
22.1.0 455 12/9/2023
22.0.2 464 12/1/2023
22.0.1 484 11/16/2023
22.0.0 473 11/14/2023
21.1.0 539 10/9/2023
21.0.4 567 9/15/2023
21.0.3 744 7/9/2023
21.0.2 682 7/6/2023
21.0.1 755 5/27/2023
21.0.0 784 4/15/2023
20.2.4 855 3/27/2023
20.2.3 792 3/17/2023
20.2.2 837 3/14/2023
20.2.1 816 3/11/2023
20.2.0 830 3/7/2023
20.1.6 844 2/23/2023
20.1.5 868 2/9/2023
20.1.4 868 1/28/2023
20.1.3 902 12/21/2022
20.1.2 950 12/14/2022
20.1.1 945 12/12/2022
20.1.0 925 12/4/2022
20.0.4 1,002 11/30/2022
20.0.3 1,055 10/28/2022
20.0.2 1,018 10/26/2022
20.0.1 1,054 10/21/2022
20.0.0 1,088 10/1/2022
19.4.1 1,122 9/10/2022
19.4.0 1,102 9/2/2022
19.3.0 1,075 8/23/2022
19.2.2 1,053 8/11/2022
19.2.1 1,115 8/6/2022
19.2.0 1,092 7/24/2022
19.1.4 1,338 5/23/2022
19.1.3 1,124 5/22/2022
19.1.2 1,202 5/18/2022
19.1.1 1,199 4/28/2022
19.1.0 1,131 4/10/2022
19.0.7 1,571 3/13/2022
19.0.6 1,187 3/7/2022
19.0.5 1,243 1/28/2022
19.0.4 1,196 1/23/2022
19.0.3 1,077 12/14/2021
19.0.2 1,066 12/11/2021
19.0.1 1,418 11/20/2021
19.0.0 1,118 11/11/2021
19.0.0-rc.net60.2 168 9/26/2021
19.0.0-rc.net60.1 218 9/16/2021
18.1.6 1,175 9/26/2021
18.1.5 2,331 9/7/2021
18.1.4 1,112 9/6/2021
18.1.3 1,122 8/19/2021
18.1.2 1,179 8/8/2021
18.1.1 1,184 8/5/2021
18.1.0 1,258 8/1/2021
18.0.1 1,187 7/30/2021
18.0.0 1,185 7/26/2021
17.0.8 1,169 7/7/2021
17.0.7 1,160 6/16/2021
17.0.6 1,123 6/5/2021
17.0.5 1,168 5/28/2021
17.0.4 1,232 5/4/2021
17.0.3 1,216 5/1/2021
17.0.2 1,150 4/22/2021
17.0.1 1,148 4/18/2021
17.0.0 1,167 3/26/2021
16.5.6 1,152 3/25/2021
16.5.5 1,127 3/23/2021
16.5.4 1,166 3/9/2021
16.5.3 1,190 2/26/2021
16.5.2 1,171 2/23/2021
16.5.1 1,160 2/21/2021
16.5.0 1,161 2/17/2021
16.4.5 1,184 2/15/2021
16.4.4 1,164 2/5/2021
16.4.3 1,117 1/27/2021
16.4.2 1,173 1/22/2021
16.4.1 1,155 1/21/2021
16.4.0 1,172 1/11/2021
16.3.3 1,181 1/8/2021
16.3.2 1,194 1/3/2021
16.3.1 1,238 12/31/2020
16.3.0 1,160 12/30/2020
16.2.1 1,211 12/27/2020
16.2.0 1,469 10/13/2020
16.1.5 1,311 10/4/2020
16.1.4 1,291 9/17/2020
16.1.3 1,325 9/13/2020
16.1.2 1,211 9/9/2020
16.1.1 1,241 9/3/2020
16.1.0 1,244 8/19/2020
16.0.3 1,274 8/15/2020
16.0.2 1,228 8/9/2020
16.0.1 1,337 8/8/2020
16.0.0 1,239 8/7/2020
15.3.0 2,146 7/23/2020
15.2.3 1,338 7/14/2020
15.2.2 1,327 5/19/2020
15.2.1 1,281 5/12/2020
15.2.0 1,311 5/9/2020
15.1.1 1,374 5/4/2020
15.1.0 1,400 4/13/2020
15.0.5 1,281 3/18/2020
15.0.4 1,309 2/28/2020
15.0.3 1,305 2/26/2020
15.0.2 1,393 1/20/2020
15.0.1 1,338 1/10/2020
15.0.0 1,366 12/17/2019
14.9.1 1,356 11/30/2019
14.9.0 1,289 11/29/2019
14.8.1 1,321 11/26/2019
14.8.0 1,328 11/20/2019
14.7.0 2,804 10/9/2019
14.6.6 1,273 10/8/2019
14.6.5 1,299 9/27/2019
14.6.4 1,371 9/21/2019
14.6.3 1,741 8/12/2019
14.6.2 1,390 8/3/2019
14.6.1 1,421 8/3/2019
14.6.0 1,413 7/26/2019
14.5.7 1,416 7/18/2019
14.5.6 1,362 7/10/2019
14.5.5 1,379 7/1/2019
14.5.4 1,444 6/17/2019
14.5.3 1,423 6/5/2019
14.5.2 1,395 5/30/2019
14.5.1 1,389 5/28/2019
14.5.0 1,519 5/24/2019
14.4.0 1,465 5/22/2019
14.3.4 1,411 5/14/2019
14.3.3 1,345 5/9/2019
14.3.2 1,572 4/30/2019
14.3.1 1,404 4/27/2019
14.3.0 1,457 4/24/2019
14.2.3 1,474 4/17/2019
14.2.2 1,421 4/10/2019
14.2.1 1,427 4/5/2019
14.2.0 1,458 3/16/2019
14.1.1 1,477 3/8/2019
14.1.0 1,577 2/11/2019
14.0.4 1,579 1/31/2019
14.0.3 1,514 1/22/2019
14.0.2 1,674 12/15/2018
14.0.1 1,581 11/29/2018
14.0.0 1,566 11/19/2018
13.3.0 1,638 11/16/2018
13.2.2 1,590 11/15/2018
13.2.1 1,508 11/13/2018
13.2.0 1,570 10/31/2018
13.1.5 1,517 10/31/2018
13.1.4 1,557 10/25/2018
13.1.3 1,595 10/18/2018
13.1.2 1,728 9/12/2018
13.1.1 1,634 9/11/2018
13.1.0 1,648 9/11/2018
13.0.0 1,638 8/29/2018
12.3.6 1,587 8/29/2018
12.3.5 1,646 8/22/2018
12.3.4 1,691 8/21/2018
12.3.3 26,406 8/21/2018
12.3.2 1,651 8/20/2018
12.3.1 1,684 8/20/2018
12.3.0 1,653 8/20/2018
12.2.2 1,692 8/15/2018
12.2.1 1,747 8/9/2018
12.2.0 1,670 8/8/2018
12.1.11 1,651 7/30/2018
12.1.10 1,722 7/20/2018
12.1.9 1,848 7/10/2018
12.1.8 2,949 7/2/2018
12.1.7 1,834 6/7/2018
12.1.6 1,757 6/4/2018
12.1.5 1,803 6/2/2018
12.1.4 1,756 5/25/2018
12.1.3 2,152 5/16/2018
12.1.2 1,780 5/15/2018
12.1.1 1,912 5/14/2018
12.1.0 1,846 5/9/2018
12.0.7 1,890 5/5/2018
12.0.6 1,744 5/4/2018
12.0.5 1,841 5/3/2018
12.0.4 1,903 4/30/2018
12.0.3 1,881 4/30/2018
12.0.2 1,883 4/27/2018
12.0.1 1,866 4/25/2018
12.0.0 1,755 4/22/2018
11.2.0 1,937 4/11/2018
11.1.0 1,782 4/8/2018
11.0.8 1,856 3/26/2018
11.0.7 1,732 3/20/2018
11.0.6 1,878 3/7/2018
11.0.5 2,031 2/22/2018
11.0.4 1,867 2/14/2018
11.0.3 1,845 2/12/2018
11.0.2 1,853 2/9/2018
11.0.1 1,791 1/29/2018
11.0.0 1,834 1/15/2018
10.0.3 1,842 12/29/2017
10.0.2 1,726 12/26/2017
10.0.1 1,860 12/18/2017
10.0.0 1,765 12/18/2017
9.3.0 1,837 12/17/2017
9.2.0 1,826 12/17/2017
9.1.3 1,852 12/5/2017
9.1.2 1,734 11/27/2017
9.1.1 1,813 11/21/2017
9.1.0 1,726 11/21/2017
9.0.1 1,704 11/11/2017
9.0.0 1,712 11/10/2017
8.7.0 1,741 11/9/2017
8.6.0 1,693 11/9/2017
8.5.0 1,725 10/3/2017
8.4.0 1,772 10/3/2017
8.3.1 2,035 9/8/2017
8.3.0 1,770 9/8/2017
8.2.0 1,752 9/4/2017
8.1.0 1,818 8/22/2017
8.0.0 1,857 8/19/2017
7.1.3 1,742 8/14/2017
7.1.2 1,750 8/2/2017
7.1.1 1,691 7/26/2017
7.1.0 1,750 7/5/2017
7.0.9 1,710 6/28/2017
7.0.8 1,828 6/19/2017
7.0.6 1,778 4/7/2017
7.0.5 1,709 3/21/2017
7.0.4 1,745 3/21/2017
7.0.3 1,731 3/20/2017
7.0.2 1,733 3/13/2017
7.0.0 1,805 3/1/2017
6.2.0 1,809 2/25/2017
6.1.0 1,824 2/14/2017
6.0.0 1,862 2/9/2017
5.3.0 1,768 2/5/2017
5.2.0 1,702 1/26/2017
5.1.0 1,738 1/19/2017
5.0.0 1,746 1/7/2017
4.11.0 1,807 1/5/2017
4.10.0 1,805 12/31/2016
4.9.0 1,728 12/26/2016
4.8.0 3,463 12/17/2016
4.7.0 1,837 12/8/2016
4.6.5 1,762 12/4/2016
4.6.4 1,751 11/25/2016
4.6.2 3,436 11/18/2016
4.6.1 1,817 11/15/2016
4.6.0 1,746 11/11/2016
4.5.9 3,677 11/2/2016
4.5.8 1,900 11/2/2016
4.5.7 3,579 10/26/2016
4.5.6 1,802 10/6/2016
4.5.5 1,792 10/3/2016
4.5.4 1,745 10/2/2016
4.5.3 1,774 9/30/2016
4.5.2 3,527 9/28/2016
4.5.1 3,470 9/28/2016
4.5.0 3,409 9/28/2016
4.4.0 3,554 9/23/2016
4.3.0 1,889 9/22/2016
4.2.0 2,037 9/19/2016
4.1.1 1,809 9/13/2016
4.1.0 1,791 9/13/2016