Audit.WCF 24.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Audit.WCF --version 24.0.1
NuGet\Install-Package Audit.WCF -Version 24.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.WCF" Version="24.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Audit.WCF --version 24.0.1
#r "nuget: Audit.WCF, 24.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.
// Install Audit.WCF as a Cake Addin
#addin nuget:?package=Audit.WCF&version=24.0.1

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

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)

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.

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 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:

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 Fault details when the operation fails
Result Object The result object value
InputParameters Array of AuditWcfEventElement Input parameters object values
OutputParameters Array of AuditWcfEventElement Output parameters object values

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 The detail object related to the fault

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:

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
25.0.4 134 3/24/2024
25.0.3 173 3/13/2024
25.0.2 151 3/12/2024
25.0.1 169 2/28/2024
25.0.0 206 2/16/2024
24.0.1 253 2/12/2024
24.0.0 223 2/12/2024
23.0.0 495 12/14/2023
22.1.0 415 12/9/2023
22.0.2 423 12/1/2023
22.0.1 455 11/16/2023
22.0.0 434 11/14/2023
21.1.0 506 10/9/2023
21.0.4 540 9/15/2023
21.0.3 700 7/9/2023
21.0.2 657 7/6/2023
21.0.1 715 5/27/2023
21.0.0 760 4/15/2023
20.2.4 812 3/27/2023
20.2.3 769 3/17/2023
20.2.2 797 3/14/2023
20.2.1 792 3/11/2023
20.2.0 806 3/7/2023
20.1.6 817 2/23/2023
20.1.5 843 2/9/2023
20.1.4 844 1/28/2023
20.1.3 861 12/21/2022
20.1.2 924 12/14/2022
20.1.1 920 12/12/2022
20.1.0 885 12/4/2022
20.0.4 962 11/30/2022
20.0.3 1,025 10/28/2022
20.0.2 992 10/26/2022
20.0.1 1,028 10/21/2022
20.0.0 1,063 10/1/2022
19.4.1 1,095 9/10/2022
19.4.0 1,075 9/2/2022
19.3.0 1,047 8/23/2022
19.2.2 1,024 8/11/2022
19.2.1 1,087 8/6/2022
19.2.0 1,060 7/24/2022
19.1.4 1,285 5/23/2022
19.1.3 1,097 5/22/2022
19.1.2 1,159 5/18/2022
19.1.1 1,174 4/28/2022
19.1.0 1,103 4/10/2022
19.0.7 1,160 3/13/2022
19.0.6 1,156 3/7/2022
19.0.5 1,197 1/28/2022
19.0.4 1,168 1/23/2022
19.0.3 1,049 12/14/2021
19.0.2 1,022 12/11/2021
19.0.1 1,374 11/20/2021
19.0.0 1,074 11/11/2021
19.0.0-rc.net60.2 152 9/26/2021
19.0.0-rc.net60.1 202 9/16/2021
18.1.6 1,147 9/26/2021
18.1.5 2,281 9/7/2021
18.1.4 1,085 9/6/2021
18.1.3 1,094 8/19/2021
18.1.2 1,149 8/8/2021
18.1.1 1,155 8/5/2021
18.1.0 1,213 8/1/2021
18.0.1 1,155 7/30/2021
18.0.0 1,151 7/26/2021
17.0.8 1,141 7/7/2021
17.0.7 1,132 6/16/2021
17.0.6 1,096 6/5/2021
17.0.5 1,140 5/28/2021
17.0.4 1,198 5/4/2021
17.0.3 1,185 5/1/2021
17.0.2 1,121 4/22/2021
17.0.1 1,117 4/18/2021
17.0.0 1,139 3/26/2021
16.5.6 1,124 3/25/2021
16.5.5 1,097 3/23/2021
16.5.4 1,136 3/9/2021
16.5.3 1,162 2/26/2021
16.5.2 1,143 2/23/2021
16.5.1 1,132 2/21/2021
16.5.0 1,115 2/17/2021
16.4.5 1,158 2/15/2021
16.4.4 1,136 2/5/2021
16.4.3 1,089 1/27/2021
16.4.2 1,144 1/22/2021
16.4.1 1,126 1/21/2021
16.4.0 1,143 1/11/2021
16.3.3 1,152 1/8/2021
16.3.2 1,165 1/3/2021
16.3.1 1,208 12/31/2020
16.3.0 1,115 12/30/2020
16.2.1 1,166 12/27/2020
16.2.0 1,430 10/13/2020
16.1.5 1,270 10/4/2020
16.1.4 1,257 9/17/2020
16.1.3 1,296 9/13/2020
16.1.2 1,182 9/9/2020
16.1.1 1,196 9/3/2020
16.1.0 1,200 8/19/2020
16.0.3 1,247 8/15/2020
16.0.2 1,201 8/9/2020
16.0.1 1,294 8/8/2020
16.0.0 1,210 8/7/2020
15.3.0 2,114 7/23/2020
15.2.3 1,307 7/14/2020
15.2.2 1,298 5/19/2020
15.2.1 1,254 5/12/2020
15.2.0 1,284 5/9/2020
15.1.1 1,345 5/4/2020
15.1.0 1,374 4/13/2020
15.0.5 1,254 3/18/2020
15.0.4 1,282 2/28/2020
15.0.3 1,260 2/26/2020
15.0.2 1,367 1/20/2020
15.0.1 1,311 1/10/2020
15.0.0 1,338 12/17/2019
14.9.1 1,326 11/30/2019
14.9.0 1,259 11/29/2019
14.8.1 1,291 11/26/2019
14.8.0 1,289 11/20/2019
14.7.0 1,358 10/9/2019
14.6.6 1,243 10/8/2019
14.6.5 1,269 9/27/2019
14.6.4 1,341 9/21/2019
14.6.3 1,686 8/12/2019
14.6.2 1,361 8/3/2019
14.6.1 1,391 8/3/2019
14.6.0 1,367 7/26/2019
14.5.7 1,387 7/18/2019
14.5.6 1,333 7/10/2019
14.5.5 1,349 7/1/2019
14.5.4 1,413 6/17/2019
14.5.3 1,378 6/5/2019
14.5.2 1,366 5/30/2019
14.5.1 1,360 5/28/2019
14.5.0 1,485 5/24/2019
14.4.0 1,436 5/22/2019
14.3.4 1,377 5/14/2019
14.3.3 1,316 5/9/2019
14.3.2 1,541 4/30/2019
14.3.1 1,371 4/27/2019
14.3.0 1,428 4/24/2019
14.2.3 1,442 4/17/2019
14.2.2 1,392 4/10/2019
14.2.1 1,398 4/5/2019
14.2.0 1,429 3/16/2019
14.1.1 1,448 3/8/2019
14.1.0 1,542 2/11/2019
14.0.4 1,546 1/31/2019
14.0.3 1,483 1/22/2019
14.0.2 1,635 12/15/2018
14.0.1 1,530 11/29/2018
14.0.0 1,530 11/19/2018
13.3.0 1,586 11/16/2018
13.2.2 1,556 11/15/2018
13.2.1 1,475 11/13/2018
13.2.0 1,532 10/31/2018
13.1.5 1,482 10/31/2018
13.1.4 1,505 10/25/2018
13.1.3 1,558 10/18/2018
13.1.2 1,673 9/12/2018
13.1.1 1,595 9/11/2018
13.1.0 1,610 9/11/2018
13.0.0 1,600 8/29/2018
12.3.6 1,548 8/29/2018
12.3.5 1,591 8/22/2018
12.3.4 1,629 8/21/2018
12.3.3 26,369 8/21/2018
12.3.2 1,612 8/20/2018
12.3.1 1,647 8/20/2018
12.3.0 1,615 8/20/2018
12.2.2 1,653 8/15/2018
12.2.1 1,707 8/9/2018
12.2.0 1,628 8/8/2018
12.1.11 1,613 7/30/2018
12.1.10 1,666 7/20/2018
12.1.9 1,808 7/10/2018
12.1.8 2,656 7/2/2018
12.1.7 1,778 6/7/2018
12.1.6 1,716 6/4/2018
12.1.5 1,764 6/2/2018
12.1.4 1,716 5/25/2018
12.1.3 2,098 5/16/2018
12.1.2 1,744 5/15/2018
12.1.1 1,873 5/14/2018
12.1.0 1,805 5/9/2018
12.0.7 1,849 5/5/2018
12.0.6 1,707 5/4/2018
12.0.5 1,804 5/3/2018
12.0.4 1,866 4/30/2018
12.0.3 1,841 4/30/2018
12.0.2 1,844 4/27/2018
12.0.1 1,814 4/25/2018
12.0.0 1,702 4/22/2018
11.2.0 1,896 4/11/2018
11.1.0 1,745 4/8/2018
11.0.8 1,815 3/26/2018
11.0.7 1,695 3/20/2018
11.0.6 1,840 3/7/2018
11.0.5 1,965 2/22/2018
11.0.4 1,827 2/14/2018
11.0.3 1,802 2/12/2018
11.0.2 1,812 2/9/2018
11.0.1 1,753 1/29/2018
11.0.0 1,792 1/15/2018
10.0.3 1,802 12/29/2017
10.0.2 1,689 12/26/2017
10.0.1 1,820 12/18/2017
10.0.0 1,726 12/18/2017
9.3.0 1,797 12/17/2017
9.2.0 1,786 12/17/2017
9.1.3 1,812 12/5/2017
9.1.2 1,695 11/27/2017
9.1.1 1,774 11/21/2017
9.1.0 1,685 11/21/2017
9.0.1 1,665 11/11/2017
9.0.0 1,675 11/10/2017
8.7.0 1,702 11/9/2017
8.6.0 1,655 11/9/2017
8.5.0 1,686 10/3/2017
8.4.0 1,734 10/3/2017
8.3.1 1,993 9/8/2017
8.3.0 1,733 9/8/2017
8.2.0 1,712 9/4/2017
8.1.0 1,777 8/22/2017
8.0.0 1,819 8/19/2017
7.1.3 1,705 8/14/2017
7.1.2 1,710 8/2/2017
7.1.1 1,652 7/26/2017
7.1.0 1,713 7/5/2017
7.0.9 1,670 6/28/2017
7.0.8 1,788 6/19/2017
7.0.6 1,736 4/7/2017
7.0.5 1,674 3/21/2017
7.0.4 1,704 3/21/2017
7.0.3 1,691 3/20/2017
7.0.2 1,696 3/13/2017
7.0.0 1,764 3/1/2017
6.2.0 1,771 2/25/2017
6.1.0 1,783 2/14/2017
6.0.0 1,824 2/9/2017
5.3.0 1,725 2/5/2017
5.2.0 1,665 1/26/2017
5.1.0 1,682 1/19/2017
5.0.0 1,708 1/7/2017
4.11.0 1,765 1/5/2017
4.10.0 1,766 12/31/2016
4.9.0 1,688 12/26/2016
4.8.0 3,422 12/17/2016
4.7.0 1,797 12/8/2016
4.6.5 1,723 12/4/2016
4.6.4 1,712 11/25/2016
4.6.2 3,394 11/18/2016
4.6.1 1,774 11/15/2016
4.6.0 1,704 11/11/2016
4.5.9 3,641 11/2/2016
4.5.8 1,858 11/2/2016
4.5.7 3,538 10/26/2016
4.5.6 1,760 10/6/2016
4.5.5 1,753 10/3/2016
4.5.4 1,706 10/2/2016
4.5.3 1,735 9/30/2016
4.5.2 3,488 9/28/2016
4.5.1 3,432 9/28/2016
4.5.0 3,370 9/28/2016
4.4.0 3,514 9/23/2016
4.3.0 1,852 9/22/2016
4.2.0 2,000 9/19/2016
4.1.1 1,749 9/13/2016
4.1.0 1,753 9/13/2016