This documentation is archived and is not being maintained.

ServiceSecurityAuditBehavior Class

Specifies the audit behavior of security events. In general, the security events consist of authentication events such as transport, message or negotiate authentication and authorization event. For more information, see ServiceAuthorizationManager.

Namespace:  System.ServiceModel.Description
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public sealed class ServiceSecurityAuditBehavior : IServiceBehavior

The ServiceSecurityAuditBehavior class is used to audit Windows Communication Foundation (WCF) authentication events. When auditing is enabled, either successful or failed authentication attempts (or both) can be audited. The events are written to one of three event logs: application, security, or the default log for the operating system version. The event logs can all be viewed using the Windows Event viewer.

Use this class to specify which event log is written to, as well as kinds of authentication events to write. You can also specify whether to suppress audit failures by setting the SuppressAuditFailure property to false (the default is true).

For more information about auditing security events for WCF applications, see Auditing Security Events.

To specify audit behavior in configuration, use the <serviceSecurityAudit> element.

The following code creates an instance of the ServiceHost class and adds a new ServiceSecurityAuditBehavior to its collection of behaviors.

public static void Main()
    // Get base address from appsettings in configuration.
    Uri baseAddress = new Uri(ConfigurationManager.

    // Create a ServiceHost for the CalculatorService type  
    // and provide the base address. 
    using (ServiceHost serviceHost = new 
        ServiceHost(typeof(CalculatorService), baseAddress))
        // Create a new auditing behavior and set the log location.
        ServiceSecurityAuditBehavior newAudit = 
            new ServiceSecurityAuditBehavior();
        newAudit.AuditLogLocation = 
        newAudit.MessageAuthenticationAuditLevel = 
        newAudit.ServiceAuthorizationAuditLevel = 
        newAudit.SuppressAuditFailure = false;
        // Remove the old behavior and add the new.
        // Open the ServiceHostBase to create listeners  
        // and start listening for messages.

        // The service can now be accessed.
        Console.WriteLine("The service is ready.");
        Console.WriteLine("Press <ENTER> to terminate service.");

        // Close the ServiceHostBase to shutdown the service.


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0