AuditLevel 枚举

定义

指定审核安全事件的时间。Specifies when to audit security events.

public enum class AuditLevel
public enum AuditLevel
type AuditLevel = 
Public Enum AuditLevel
继承
AuditLevel

字段

Failure 2

仅记录失败的与安全相关的事件。Only failed security-related events will be recorded.

None 0

不记录任何事件。No events will be recorded. 这是默认设置。This is the default.

Success 1

仅记录成功的与安全相关的事件。Only successful security-related events will be recorded.

SuccessOrFailure 3

同时记录失败和成功的与安全相关的事件。Both failed and successful security-related events will be recorded.

示例

下面的示例将 MessageAuthenticationAuditLevelServiceAuthorizationAuditLevel 属性设置为 AuditLevel 值之一。The following example sets the MessageAuthenticationAuditLevel and ServiceAuthorizationAuditLevel properties to one of the AuditLevel values.

public static void Main()
{
    // Get base address from appsettings in configuration.
    Uri baseAddress = new Uri(ConfigurationManager.
        AppSettings["baseAddress"]);

    // 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 = 
            AuditLogLocation.Application;
        newAudit.MessageAuthenticationAuditLevel = 
            AuditLevel.SuccessOrFailure;
        newAudit.ServiceAuthorizationAuditLevel = 
            AuditLevel.SuccessOrFailure;
        newAudit.SuppressAuditFailure = false;
        // Remove the old behavior and add the new.
        serviceHost.Description.
            Behaviors.Remove<ServiceSecurityAuditBehavior>();
        serviceHost.Description.Behaviors.Add(newAudit);
        // Open the ServiceHostBase to create listeners 
        // and start listening for messages.
        serviceHost.Open();

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

        // Close the ServiceHostBase to shutdown the service.
        serviceHost.Close();
    }
}
Public Shared Sub Main() 
    ' Get base address from appsettings in configuration.
    Dim baseAddress As New Uri(ConfigurationManager.AppSettings("baseAddress"))
    
    ' Create a ServiceHost for the CalculatorService type 
    ' and provide the base address.
    Dim serviceHost As New ServiceHost(GetType(CalculatorService), baseAddress)
    Try
        ' Create a new auditing behavior and set the log location.
        Dim newAudit As New ServiceSecurityAuditBehavior()
        newAudit.AuditLogLocation = AuditLogLocation.Application
        newAudit.MessageAuthenticationAuditLevel = _
            AuditLevel.SuccessOrFailure
        newAudit.ServiceAuthorizationAuditLevel = _
            AuditLevel.SuccessOrFailure
        newAudit.SuppressAuditFailure = False
        ' Remove the old behavior and add the new.
        serviceHost.Description.Behaviors.Remove(Of ServiceSecurityAuditBehavior)
        serviceHost.Description.Behaviors.Add(newAudit)
        ' Open the ServiceHostBase to create listeners 
        ' and start listening for messages.
        serviceHost.Open()
        
        ' The service can now be accessed.
        Console.WriteLine("The service is ready.")
        Console.WriteLine("Press <ENTER> to terminate service.")
        Console.WriteLine()
        Console.ReadLine()
        
        ' Close the ServiceHostBase to shutdown the service.
        serviceHost.Close()
    Finally
    End Try

End Sub 

注解

创建需要对调用方进行身份验证和/或授权的 Windows Communication Foundation (WCF) 应用程序时, 可以指定记录与安全相关的事件以获得成功、失败或两者。When creating a Windows Communication Foundation (WCF) application that requires authentication and/or authorization of the callers, you can specify that events related to security be recorded for either success, failure, or both. 审核的级别由此枚举决定。The level of auditing is determined by this enumeration.

指定审核日志的位置的方法是:通过将 AuditLogLocation 类的 ServiceSecurityAuditBehavior 属性设置为 AuditLogLocation 值之一。The location of the audit log is specified by setting the AuditLogLocation property of the ServiceSecurityAuditBehavior class to one of the AuditLogLocation values.

有关审核的详细信息, 请参阅审核For more information about auditing, see Auditing.

还可以使用 <serviceSecurityAudit> 绑定指定审核行为。You can also specify audit behavior using the <serviceSecurityAudit> binding.

适用于

另请参阅