AuditLogLocation 列舉

定義

指定寫入安全性相關事件記錄的位置。Specifies the location where security-related event logs are written.

public enum class AuditLogLocation
public enum AuditLogLocation
type AuditLogLocation = 
Public Enum AuditLogLocation
繼承
AuditLogLocation

欄位

Application 1

指定事件記錄檔中的應用程式記錄。Specifies the Application log in the event log.

Default 0

指定作業系統所決定的預設位置。Specifies the default location, which is determined by the operating system. 如果支援寫入安全性記錄檔 (例如在 Windows VistaWindows VistaWindows Server 2003Windows Server 2003 (含) 以後平台),預設的記錄檔位置為安全性記錄檔。If writing to the Security log is supported (such as on Windows VistaWindows Vista and Windows Server 2003Windows Server 2003 and later platforms), the default log location is the Security log. 否則,(例如在 Windows XP SP2Windows XP SP2),預設的記錄檔位置就是應用程式記錄檔。Otherwise (such as in Windows XP SP2Windows XP SP2), the default log location is the Application log.

Security 2

指定事件記錄檔中的安全性記錄。Specifies the Security log in the event log. 呼叫的執行緒必須具備 SeAuditPrivilege 才能寫入安全性記錄檔。The calling thread must have SeAuditPrivilege to be able to write to the Security log.

範例

下列範例會將 ServiceSecurityAuditBehavior.AuditLogLocation 屬性設定為其中一個 AuditLogLocation 值:The following example sets the ServiceSecurityAuditBehavior.AuditLogLocation property to one of the AuditLogLocation 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 callers, you can specify that events related to security be recorded for either success, failure, or both. 記錄的位置是由此列舉所決定。The location of the log is determined by this enumeration.

您可以將 MessageAuthenticationAuditLevelServiceAuthorizationAuditLevel 類別的 ServiceSecurityAuditBehavior 屬性設為其中一個 AuditLevel 值來指定稽核記錄的層級。The level of the audit log is specified by setting the MessageAuthenticationAuditLevel or the ServiceAuthorizationAuditLevel property of the ServiceSecurityAuditBehavior class to one of the AuditLevel values.

您也可以使用<serviceSecurityAudit>系結來指定 audit 行為。You can also specify audit behavior using the <serviceSecurityAudit> binding.

重要

如果 AuditLogLocation 屬性設定為 [安全性],而且未在 Local Security Policy中設定 Audit Object Access,則 audit 事件不會寫入安全性記錄檔中。If the AuditLogLocation property is set to Security and Audit Object Access is not set in the Local Security Policy, audit events will not be written to the Security log. 這時不會傳回任何失敗,但是稽核項目也不會寫入安全性記錄檔中。No failure is returned, but audit entries will not be written to the Security log. 此外,呼叫的執行緒必須具備 SeAuditPrivilege 才能寫入安全性記錄檔。In addition, the calling thread must have SeAuditPrivilege to be able to write to the Security log.

預設值視作業系統而定Default Dependent on Operating System

將屬性設定為預設值時,作業系統會決定實際寫入的記錄檔。When setting the property to the Default value, the operating system determines which log will actually be written to. 如需詳細資訊,請參閱「審核」。For more information, see Auditing.

適用於

另請參閱