Audit.WCF
27.1.1
dotnet add package Audit.WCF --version 27.1.1
NuGet\Install-Package Audit.WCF -Version 27.1.1
<PackageReference Include="Audit.WCF" Version="27.1.1" />
paket add Audit.WCF --version 27.1.1
#r "nuget: Audit.WCF, 27.1.1"
// Install Audit.WCF as a Cake Addin #addin nuget:?package=Audit.WCF&version=27.1.1 // Install Audit.WCF as a Cake Tool #tool nuget:?package=Audit.WCF&version=27.1.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
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 | Versions 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. |
-
.NETFramework 4.6.2
- Audit.NET (>= 27.1.1)
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.1.1 | 76 | 10/28/2024 |
27.1.0 | 91 | 10/24/2024 |
27.0.3 | 98 | 9/25/2024 |
27.0.2 | 101 | 9/19/2024 |
27.0.1 | 106 | 9/4/2024 |
27.0.0 | 102 | 9/3/2024 |
26.0.1 | 133 | 8/22/2024 |
26.0.0 | 105 | 7/19/2024 |
25.0.7 | 134 | 7/4/2024 |
25.0.6 | 101 | 6/24/2024 |
25.0.5 | 106 | 6/18/2024 |
25.0.4 | 177 | 3/24/2024 |
25.0.3 | 203 | 3/13/2024 |
25.0.2 | 178 | 3/12/2024 |
25.0.1 | 206 | 2/28/2024 |
25.0.0 | 230 | 2/16/2024 |
24.0.1 | 276 | 2/12/2024 |
24.0.0 | 247 | 2/12/2024 |
23.0.0 | 519 | 12/14/2023 |
22.1.0 | 450 | 12/9/2023 |
22.0.2 | 459 | 12/1/2023 |
22.0.1 | 477 | 11/16/2023 |
22.0.0 | 468 | 11/14/2023 |
21.1.0 | 532 | 10/9/2023 |
21.0.4 | 562 | 9/15/2023 |
21.0.3 | 737 | 7/9/2023 |
21.0.2 | 677 | 7/6/2023 |
21.0.1 | 750 | 5/27/2023 |
21.0.0 | 779 | 4/15/2023 |
20.2.4 | 850 | 3/27/2023 |
20.2.3 | 787 | 3/17/2023 |
20.2.2 | 832 | 3/14/2023 |
20.2.1 | 811 | 3/11/2023 |
20.2.0 | 825 | 3/7/2023 |
20.1.6 | 839 | 2/23/2023 |
20.1.5 | 863 | 2/9/2023 |
20.1.4 | 863 | 1/28/2023 |
20.1.3 | 897 | 12/21/2022 |
20.1.2 | 945 | 12/14/2022 |
20.1.1 | 940 | 12/12/2022 |
20.1.0 | 920 | 12/4/2022 |
20.0.4 | 997 | 11/30/2022 |
20.0.3 | 1,050 | 10/28/2022 |
20.0.2 | 1,013 | 10/26/2022 |
20.0.1 | 1,049 | 10/21/2022 |
20.0.0 | 1,083 | 10/1/2022 |
19.4.1 | 1,117 | 9/10/2022 |
19.4.0 | 1,097 | 9/2/2022 |
19.3.0 | 1,070 | 8/23/2022 |
19.2.2 | 1,048 | 8/11/2022 |
19.2.1 | 1,110 | 8/6/2022 |
19.2.0 | 1,087 | 7/24/2022 |
19.1.4 | 1,330 | 5/23/2022 |
19.1.3 | 1,119 | 5/22/2022 |
19.1.2 | 1,197 | 5/18/2022 |
19.1.1 | 1,194 | 4/28/2022 |
19.1.0 | 1,126 | 4/10/2022 |
19.0.7 | 1,407 | 3/13/2022 |
19.0.6 | 1,182 | 3/7/2022 |
19.0.5 | 1,238 | 1/28/2022 |
19.0.4 | 1,191 | 1/23/2022 |
19.0.3 | 1,072 | 12/14/2021 |
19.0.2 | 1,061 | 12/11/2021 |
19.0.1 | 1,413 | 11/20/2021 |
19.0.0 | 1,113 | 11/11/2021 |
19.0.0-rc.net60.2 | 165 | 9/26/2021 |
19.0.0-rc.net60.1 | 215 | 9/16/2021 |
18.1.6 | 1,170 | 9/26/2021 |
18.1.5 | 2,326 | 9/7/2021 |
18.1.4 | 1,107 | 9/6/2021 |
18.1.3 | 1,117 | 8/19/2021 |
18.1.2 | 1,174 | 8/8/2021 |
18.1.1 | 1,179 | 8/5/2021 |
18.1.0 | 1,253 | 8/1/2021 |
18.0.1 | 1,182 | 7/30/2021 |
18.0.0 | 1,178 | 7/26/2021 |
17.0.8 | 1,164 | 7/7/2021 |
17.0.7 | 1,155 | 6/16/2021 |
17.0.6 | 1,118 | 6/5/2021 |
17.0.5 | 1,163 | 5/28/2021 |
17.0.4 | 1,224 | 5/4/2021 |
17.0.3 | 1,209 | 5/1/2021 |
17.0.2 | 1,145 | 4/22/2021 |
17.0.1 | 1,141 | 4/18/2021 |
17.0.0 | 1,162 | 3/26/2021 |
16.5.6 | 1,147 | 3/25/2021 |
16.5.5 | 1,120 | 3/23/2021 |
16.5.4 | 1,159 | 3/9/2021 |
16.5.3 | 1,185 | 2/26/2021 |
16.5.2 | 1,166 | 2/23/2021 |
16.5.1 | 1,155 | 2/21/2021 |
16.5.0 | 1,156 | 2/17/2021 |
16.4.5 | 1,179 | 2/15/2021 |
16.4.4 | 1,159 | 2/5/2021 |
16.4.3 | 1,112 | 1/27/2021 |
16.4.2 | 1,168 | 1/22/2021 |
16.4.1 | 1,150 | 1/21/2021 |
16.4.0 | 1,167 | 1/11/2021 |
16.3.3 | 1,176 | 1/8/2021 |
16.3.2 | 1,189 | 1/3/2021 |
16.3.1 | 1,231 | 12/31/2020 |
16.3.0 | 1,155 | 12/30/2020 |
16.2.1 | 1,206 | 12/27/2020 |
16.2.0 | 1,461 | 10/13/2020 |
16.1.5 | 1,304 | 10/4/2020 |
16.1.4 | 1,286 | 9/17/2020 |
16.1.3 | 1,320 | 9/13/2020 |
16.1.2 | 1,206 | 9/9/2020 |
16.1.1 | 1,236 | 9/3/2020 |
16.1.0 | 1,239 | 8/19/2020 |
16.0.3 | 1,269 | 8/15/2020 |
16.0.2 | 1,223 | 8/9/2020 |
16.0.1 | 1,332 | 8/8/2020 |
16.0.0 | 1,232 | 8/7/2020 |
15.3.0 | 2,137 | 7/23/2020 |
15.2.3 | 1,332 | 7/14/2020 |
15.2.2 | 1,322 | 5/19/2020 |
15.2.1 | 1,276 | 5/12/2020 |
15.2.0 | 1,306 | 5/9/2020 |
15.1.1 | 1,369 | 5/4/2020 |
15.1.0 | 1,395 | 4/13/2020 |
15.0.5 | 1,276 | 3/18/2020 |
15.0.4 | 1,304 | 2/28/2020 |
15.0.3 | 1,298 | 2/26/2020 |
15.0.2 | 1,388 | 1/20/2020 |
15.0.1 | 1,333 | 1/10/2020 |
15.0.0 | 1,361 | 12/17/2019 |
14.9.1 | 1,349 | 11/30/2019 |
14.9.0 | 1,282 | 11/29/2019 |
14.8.1 | 1,314 | 11/26/2019 |
14.8.0 | 1,321 | 11/20/2019 |
14.7.0 | 2,104 | 10/9/2019 |
14.6.6 | 1,266 | 10/8/2019 |
14.6.5 | 1,292 | 9/27/2019 |
14.6.4 | 1,364 | 9/21/2019 |
14.6.3 | 1,734 | 8/12/2019 |
14.6.2 | 1,383 | 8/3/2019 |
14.6.1 | 1,414 | 8/3/2019 |
14.6.0 | 1,389 | 7/26/2019 |
14.5.7 | 1,409 | 7/18/2019 |
14.5.6 | 1,355 | 7/10/2019 |
14.5.5 | 1,372 | 7/1/2019 |
14.5.4 | 1,435 | 6/17/2019 |
14.5.3 | 1,416 | 6/5/2019 |
14.5.2 | 1,388 | 5/30/2019 |
14.5.1 | 1,382 | 5/28/2019 |
14.5.0 | 1,512 | 5/24/2019 |
14.4.0 | 1,458 | 5/22/2019 |
14.3.4 | 1,400 | 5/14/2019 |
14.3.3 | 1,338 | 5/9/2019 |
14.3.2 | 1,563 | 4/30/2019 |
14.3.1 | 1,393 | 4/27/2019 |
14.3.0 | 1,450 | 4/24/2019 |
14.2.3 | 1,464 | 4/17/2019 |
14.2.2 | 1,414 | 4/10/2019 |
14.2.1 | 1,420 | 4/5/2019 |
14.2.0 | 1,451 | 3/16/2019 |
14.1.1 | 1,470 | 3/8/2019 |
14.1.0 | 1,568 | 2/11/2019 |
14.0.4 | 1,572 | 1/31/2019 |
14.0.3 | 1,507 | 1/22/2019 |
14.0.2 | 1,665 | 12/15/2018 |
14.0.1 | 1,572 | 11/29/2018 |
14.0.0 | 1,557 | 11/19/2018 |
13.3.0 | 1,629 | 11/16/2018 |
13.2.2 | 1,581 | 11/15/2018 |
13.2.1 | 1,499 | 11/13/2018 |
13.2.0 | 1,556 | 10/31/2018 |
13.1.5 | 1,505 | 10/31/2018 |
13.1.4 | 1,545 | 10/25/2018 |
13.1.3 | 1,581 | 10/18/2018 |
13.1.2 | 1,718 | 9/12/2018 |
13.1.1 | 1,624 | 9/11/2018 |
13.1.0 | 1,638 | 9/11/2018 |
13.0.0 | 1,628 | 8/29/2018 |
12.3.6 | 1,575 | 8/29/2018 |
12.3.5 | 1,636 | 8/22/2018 |
12.3.4 | 1,681 | 8/21/2018 |
12.3.3 | 26,394 | 8/21/2018 |
12.3.2 | 1,638 | 8/20/2018 |
12.3.1 | 1,672 | 8/20/2018 |
12.3.0 | 1,642 | 8/20/2018 |
12.2.2 | 1,682 | 8/15/2018 |
12.2.1 | 1,734 | 8/9/2018 |
12.2.0 | 1,659 | 8/8/2018 |
12.1.11 | 1,640 | 7/30/2018 |
12.1.10 | 1,713 | 7/20/2018 |
12.1.9 | 1,837 | 7/10/2018 |
12.1.8 | 2,843 | 7/2/2018 |
12.1.7 | 1,825 | 6/7/2018 |
12.1.6 | 1,748 | 6/4/2018 |
12.1.5 | 1,794 | 6/2/2018 |
12.1.4 | 1,747 | 5/25/2018 |
12.1.3 | 2,141 | 5/16/2018 |
12.1.2 | 1,771 | 5/15/2018 |
12.1.1 | 1,901 | 5/14/2018 |
12.1.0 | 1,837 | 5/9/2018 |
12.0.7 | 1,881 | 5/5/2018 |
12.0.6 | 1,735 | 5/4/2018 |
12.0.5 | 1,832 | 5/3/2018 |
12.0.4 | 1,894 | 4/30/2018 |
12.0.3 | 1,872 | 4/30/2018 |
12.0.2 | 1,874 | 4/27/2018 |
12.0.1 | 1,855 | 4/25/2018 |
12.0.0 | 1,746 | 4/22/2018 |
11.2.0 | 1,928 | 4/11/2018 |
11.1.0 | 1,773 | 4/8/2018 |
11.0.8 | 1,847 | 3/26/2018 |
11.0.7 | 1,723 | 3/20/2018 |
11.0.6 | 1,869 | 3/7/2018 |
11.0.5 | 2,022 | 2/22/2018 |
11.0.4 | 1,858 | 2/14/2018 |
11.0.3 | 1,836 | 2/12/2018 |
11.0.2 | 1,844 | 2/9/2018 |
11.0.1 | 1,782 | 1/29/2018 |
11.0.0 | 1,825 | 1/15/2018 |
10.0.3 | 1,833 | 12/29/2017 |
10.0.2 | 1,717 | 12/26/2017 |
10.0.1 | 1,851 | 12/18/2017 |
10.0.0 | 1,756 | 12/18/2017 |
9.3.0 | 1,828 | 12/17/2017 |
9.2.0 | 1,817 | 12/17/2017 |
9.1.3 | 1,843 | 12/5/2017 |
9.1.2 | 1,725 | 11/27/2017 |
9.1.1 | 1,804 | 11/21/2017 |
9.1.0 | 1,717 | 11/21/2017 |
9.0.1 | 1,695 | 11/11/2017 |
9.0.0 | 1,703 | 11/10/2017 |
8.7.0 | 1,732 | 11/9/2017 |
8.6.0 | 1,684 | 11/9/2017 |
8.5.0 | 1,716 | 10/3/2017 |
8.4.0 | 1,763 | 10/3/2017 |
8.3.1 | 2,026 | 9/8/2017 |
8.3.0 | 1,761 | 9/8/2017 |
8.2.0 | 1,743 | 9/4/2017 |
8.1.0 | 1,809 | 8/22/2017 |
8.0.0 | 1,848 | 8/19/2017 |
7.1.3 | 1,733 | 8/14/2017 |
7.1.2 | 1,739 | 8/2/2017 |
7.1.1 | 1,682 | 7/26/2017 |
7.1.0 | 1,741 | 7/5/2017 |
7.0.9 | 1,701 | 6/28/2017 |
7.0.8 | 1,819 | 6/19/2017 |
7.0.6 | 1,769 | 4/7/2017 |
7.0.5 | 1,700 | 3/21/2017 |
7.0.4 | 1,734 | 3/21/2017 |
7.0.3 | 1,722 | 3/20/2017 |
7.0.2 | 1,724 | 3/13/2017 |
7.0.0 | 1,796 | 3/1/2017 |
6.2.0 | 1,800 | 2/25/2017 |
6.1.0 | 1,815 | 2/14/2017 |
6.0.0 | 1,853 | 2/9/2017 |
5.3.0 | 1,759 | 2/5/2017 |
5.2.0 | 1,693 | 1/26/2017 |
5.1.0 | 1,729 | 1/19/2017 |
5.0.0 | 1,737 | 1/7/2017 |
4.11.0 | 1,798 | 1/5/2017 |
4.10.0 | 1,796 | 12/31/2016 |
4.9.0 | 1,719 | 12/26/2016 |
4.8.0 | 3,454 | 12/17/2016 |
4.7.0 | 1,828 | 12/8/2016 |
4.6.5 | 1,753 | 12/4/2016 |
4.6.4 | 1,742 | 11/25/2016 |
4.6.2 | 3,425 | 11/18/2016 |
4.6.1 | 1,804 | 11/15/2016 |
4.6.0 | 1,737 | 11/11/2016 |
4.5.9 | 3,668 | 11/2/2016 |
4.5.8 | 1,891 | 11/2/2016 |
4.5.7 | 3,568 | 10/26/2016 |
4.5.6 | 1,793 | 10/6/2016 |
4.5.5 | 1,783 | 10/3/2016 |
4.5.4 | 1,736 | 10/2/2016 |
4.5.3 | 1,765 | 9/30/2016 |
4.5.2 | 3,518 | 9/28/2016 |
4.5.1 | 3,461 | 9/28/2016 |
4.5.0 | 3,400 | 9/28/2016 |
4.4.0 | 3,545 | 9/23/2016 |
4.3.0 | 1,880 | 9/22/2016 |
4.2.0 | 2,028 | 9/19/2016 |
4.1.1 | 1,800 | 9/13/2016 |
4.1.0 | 1,782 | 9/13/2016 |