EventLog EventLog EventLog EventLog Class

定義

提供與 Windows 事件記錄檔的互動。Provides interaction with Windows event logs.

public ref class EventLog : System::ComponentModel::Component, System::ComponentModel::ISupportInitialize
public class EventLog : System.ComponentModel.Component, System.ComponentModel.ISupportInitialize
type EventLog = class
    inherit Component
    interface ISupportInitialize
Public Class EventLog
Inherits Component
Implements ISupportInitialize
繼承
實作

範例

下列範例會建立事件來源MySource如果尚未存在,它的項目寫入事件記錄檔MyNewLogThe following example creates the event source MySource if it doesn't already exist, and writes an entry to the event log MyNewLog.

注意

從 Windows Vista 開始,您必須以系統管理員身分執行此應用程式。Starting with Windows Vista, you must run this application as an administrator.

#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
using namespace System::Threading;
int main()
{
   
   // Create the source, if it does not already exist.
   if (  !EventLog::SourceExists( "MySource" ) )
   {
      //An event log source should not be created and immediately used.
      //There is a latency time to enable the source, it should be created
      //prior to executing the application that uses the source.
      //Execute this sample a second time to use the new source.
      EventLog::CreateEventSource( "MySource", "MyNewLog" );
      Console::WriteLine( "CreatingEventSource" );
      // The source is created.  Exit the application to allow it to be registered.
      return 0;
   }

   
   // Create an EventLog instance and assign its source.
   EventLog^ myLog = gcnew EventLog;
   myLog->Source = "MySource";
   
   // Write an informational entry to the event log.    
   myLog->WriteEntry( "Writing to event log." );
}

using System;
using System.Diagnostics;
using System.Threading;
              
class MySample{

    public static void Main(){
    
        // Create the source, if it does not already exist.
        if(!EventLog.SourceExists("MySource"))
        {
             //An event log source should not be created and immediately used.
             //There is a latency time to enable the source, it should be created
             //prior to executing the application that uses the source.
             //Execute this sample a second time to use the new source.
            EventLog.CreateEventSource("MySource", "MyNewLog");
            Console.WriteLine("CreatedEventSource");
            Console.WriteLine("Exiting, execute the application a second time to use the source.");
            // The source is created.  Exit the application to allow it to be registered.
            return;
        }
                
        // Create an EventLog instance and assign its source.
        EventLog myLog = new EventLog();
        myLog.Source = "MySource";
        
        // Write an informational entry to the event log.    
        myLog.WriteEntry("Writing to event log.");
        
    }
}
   
Option Explicit
Option Strict

Imports System
Imports System.Diagnostics
Imports System.Threading

Class MySample
    Public Shared Sub Main()
        
        If Not EventLog.SourceExists("MySource") Then
            ' Create the source, if it does not already exist.
            ' An event log source should not be created and immediately used.
            ' There is a latency time to enable the source, it should be created
            ' prior to executing the application that uses the source.
            ' Execute this sample a second time to use the new source.
            EventLog.CreateEventSource("MySource", "MyNewLog")
            Console.WriteLine("CreatingEventSource")
            'The source is created.  Exit the application to allow it to be registered.
            Return
        End If
        
        ' Create an EventLog instance and assign its source.
        Dim myLog As New EventLog()
        myLog.Source = "MySource"
        
        ' Write an informational entry to the event log.    
        myLog.WriteEntry("Writing to event log.")
    End Sub 'Main 
End Class 'MySample

備註

EventLog 可讓您存取或自訂 Windows 事件記錄檔記錄重要的軟體或硬體事件的相關資訊。EventLog lets you access or customize Windows event logs, which record information about important software or hardware events. 使用EventLog,您可以從現有的記錄檔讀取、 寫入記錄檔中的項目、 建立或刪除事件來源、 刪除記錄檔,並回應記錄項目。Using EventLog, you can read from existing logs, write entries to logs, create or delete event sources, delete logs, and respond to log entries. 建立事件來源時,您也可以建立新的記錄檔。You can also create new logs when creating an event source.

重要

此類型會實作IDisposable介面。This type implements the IDisposable interface. 當您完成使用型別時,您應該處置它直接或間接。When you have finished using the type, you should dispose of it either directly or indirectly. 若要直接處置型別,呼叫其Dispose方法中的try / catch區塊。To dispose of the type directly, call its Dispose method in a try/catch block. 若要處置它間接,使用的語言建構這類using(在 C# 中) 或Using(在 Visual Basic)。To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). 如需詳細資訊,請參閱 「 使用物件,實作 IDisposable 」 一節IDisposable介面 > 主題。For more information, see the "Using an Object that Implements IDisposable" section in the IDisposable interface topic.

除了存取個別的事件記錄檔和其項目,EventLog類別可讓您存取所有事件記錄檔的集合。In addition to providing access to individual event logs and their entries, the EventLog class lets you access the collection of all event logs. 您可以使用static的成員EventLog來刪除記錄,請取得記錄清單、 建立或刪除來源,或判斷電腦是否已包含特定的來源。You can use the static members of EventLog to delete logs, get log lists, create or delete a source, or determine if a computer already contains a particular source.

有三個預設事件記錄檔:應用程式、 系統及安全性。There are three default event logs: Application, System, and Security. 安全性記錄檔是唯讀的。A Security log is read-only. 其他應用程式和服務安裝,例如 Active Directory 中,可能會有額外的事件記錄檔。Other applications and services you install, such as Active Directory, might have additional event logs.

使用時,有一些安全性考量EventLog類別。There are security considerations when using the EventLog class. EventLog 需要EventLogPermission特定的動作,在.NET Framework 2.0 和更新版本中或在.NET Framework 1.0 和 1.1 版中的完全信任權限。EventLog requires EventLogPermission permissions for specific actions in the .NET Framework 2.0 and later versions, or full trust in the .NET Framework 1.0 and 1.1. 我們建議EventLogPermission不授與部分信任程式碼。We recommend that EventLogPermission not be granted to partially trusted code. 您應該永遠不會傳遞任何事件記錄檔物件,包括EventLogEntryCollectionEventLogEntry較不受信任的程式碼的物件。You should never pass any event log object, including EventLogEntryCollection and EventLogEntry objects, to less trusted code. 例如,建立EventLog物件,寫入項目,然後再將傳遞EventLog物件到部分受信任的程式碼可以建立安全性問題,因為能夠讀取和寫入事件記錄檔可執行動作,例如發出的程式碼事件記錄檔訊息,另一個應用程式的名稱。For example, creating an EventLog object, writing an entry, and then passing the EventLog object to partially trusted code can create a security issue, because the ability to read and write to the event log allows code to perform actions such as issuing event log messages in the name of another application.

從 Windows Vista 開始,使用者帳戶控制 (UAC) 會決定使用者的認證。Starting with Windows Vista, User Account Control (UAC) determines the credentials of a user. 如果您是內建 Administrators 群組的成員,系統會將兩個執行階段存取語彙基元 (Token) 指派給您:標準使用者存取語彙基元及管理員存取語彙基元。If you are a member of the Built-in Administrators group, you are assigned two run-time access tokens: a standard user access token and an administrator access token. 根據預設,您會屬於標準使用者角色。By default, you are in the standard user role. 若要執行的程式碼存取安全性記錄檔,您必須先將您的認證從標準使用者提高為系統管理員。To run the code that accesses the Security log, you must first elevate your credentials from standard user to administrator. 您可以藉由開啟應用程式的捷徑功能表來啟動應用程式時 (如果您使用滑鼠,以滑鼠右鍵按一下應用程式圖示),並指出您想要以系統管理員身分執行。You can do this when you start an application by opening the shortcut menu for the application (if you're using a mouse, right-click the application icon) and indicating that you want to run as an administrator.

您可以使用EventLog若要建立自訂的事件記錄檔,您可以透過伺服器檢視的 事件檢視器。You can use EventLog to create custom event logs that you can view through the server's Event Viewer. 使用RegisterDisplayName方法,以在事件檢視器中顯示您的事件記錄檔的當地語系化的名稱。Use the RegisterDisplayName method to display a localized name for your event log in the Event Viewer. 使用ModifyOverflowPolicy來設定事件記錄檔的行為,當它達到最大記錄檔大小的方法。Use the ModifyOverflowPolicy method to configure the behavior of your event log when it reaches its maximum log size.

若要讀取事件記錄檔,請指定 記錄檔名稱 (Log屬性) 和伺服器電腦名稱 (MachineName事件記錄檔的屬性。To read from an event log, specify the log name (Log property) and server computer name (MachineName property for the event log. 如果您未指定伺服器的電腦名稱,本機電腦中,"。",會假設。If you don't specify the server computer name, the local computer, ".", is assumed. 您不需要指定事件來源 (Source屬性),因為來源是只有需要寫入記錄檔。It's not necessary to specify the event source (Source property), because a source is required only for writing to logs. Entries屬性會自動填入的項目事件記錄檔的清單。The Entries property is automatically populated with the event log's list of entries.

若要寫入事件記錄檔,指定或建立事件來源 (Source屬性)。To write to an event log, specify or create an event source (Source property). 您必須具有系統管理認證,以建立新的事件來源電腦上。You must have administrative credentials on the computer to create a new event source. 事件來源會註冊您的應用程式事件記錄檔做為有效的來源項目。The event source registers your application with the event log as a valid source of entries. 您可以使用事件來源寫入一次只能有一個記錄檔。You can use the event source to write to only one log at a time. Source屬性可以是任何隨機字串,但必須是相異的電腦上的其他來源的名稱。The Source property can be any random string, but the name must be distinct from other sources on the computer. 事件來源通常是應用程式或另一個的識別字串的名稱。The event source is typically the name of the application or another identifying string. 嘗試建立重複Source值就會擲回例外狀況。Trying to create a duplicate Source value throws an exception. 不過,單一的事件記錄檔可以與多個來源相關聯。However, a single event log can be associated with multiple sources.

如果與相關聯的事件記錄檔的事件來源EventLog執行個體不存在,會建立新的事件來源。If the event source for the event log associated with the EventLog instance doesn't exist, a new event source is created. 若要建立事件來源,在 Windows Vista 和更新版本或 Windows Server 2003,您必須具有系統管理認證。To create an event source in Windows Vista and later or Windows Server 2003, you must have administrative credentials.

這項需求是因為所有的事件記錄檔,包括安全性記錄檔,必須搜尋以判斷事件來源是否為唯一。This requirement is because all event logs, including Security logs, must be searched to determine whether the event source is unique. 從 Windows Vista 開始,使用者沒有權限以存取安全性記錄檔中;因此,SecurityException就會擲回。Starting with Windows Vista, users do not have permission to access the Security log; therefore, a SecurityException is thrown.

重要

使用具名的 mutex 建立或刪除事件來源時,需要同步處理的基礎程式碼。Creating or deleting an event source requires synchronization of the underlying code by using a named mutex. 如果高特殊權限的應用程式鎖定具名的 mutex,嘗試建立或刪除事件來源產生應用程式停止回應,直到鎖定解除為止。If a highly privileged application locks the named mutex, trying to create or delete an event source causes the application to stop responding until the lock is released. 若要避免此問題,永遠不會授與UnmanagedCode不受信任的程式碼的權限。To help prevent this problem, never grant UnmanagedCode permission to untrusted code. 颾魤 ㄛUnmanagedCode權限可能會允許略過其他權限,以及只應該授與高度信任程式碼。In addition, UnmanagedCode permission potentially allows other permissions to be bypassed and should only be granted to highly trusted code.

應用程式和服務應該將寫入應用程式記錄檔或自訂的記錄檔。Applications and services should write to the Application log or to a custom log. 裝置驅動程式應該寫入至系統記錄檔。Device drivers should write to the System log. 如果您沒有明確設定Log屬性預設為應用程式記錄檔的事件記錄檔。If you do not explicitly set the Log property, the event log defaults to the Application log.

注意

沒有要保護的應用程式,從撰寫為任何已註冊的來源。There is nothing to protect an application from writing as any registered source. 如果應用程式授與Write權限,它可以寫入之事件的任何有效的來源電腦上登錄。If an application is granted Write permission, it can write events for any valid source registered on the computer.

使用WriteEventWriteEntry將事件寫入事件記錄檔的方法。Use the WriteEvent and WriteEntry methods to write events to an event log. 您必須指定要寫入事件,事件來源您必須建立並設定事件來源寫入來源的第一個項目之前。You must specify an event source to write events; you must create and configure the event source before writing the first entry with the source.

在您的應用程式的安裝期間建立新的事件來源。Create the new event source during the installation of your application. 這可讓作業系統重新整理其已註冊的事件來源的清單和其設定的時間。This allows time for the operating system to refresh its list of registered event sources and their configuration. 如果作業系統尚未重新整理其事件來源的清單,而且您嘗試寫入新的來源的事件寫入作業將會失敗。If the operating system hasn't refreshed its list of event sources, and you try to write an event with the new source, the write operation will fail. 您可以使用,以設定新的來源EventLogInstaller物件或CreateEventSource方法。You can configure a new source by using an EventLogInstaller object or the CreateEventSource method. 您必須具有系統管理認證,以建立新的事件來源電腦上。You must have administrative credentials on the computer to create a new event source.

每個來源一次; 可以寫入只有一個事件記錄檔不過,您的應用程式也可以使用多個來源,以寫入多個事件記錄檔。Each source can write to only one event log at a time; however, your application can use multiple sources to write to multiple event logs. 例如,您的應用程式可能需要多個來源設定為不同的事件記錄檔或不同的資源檔。For example, your application might require multiple sources configured for different event logs or different resource files. 若要變更現有的來源的設定詳細資料,您必須刪除來源,並再建立新的組態。To change the configuration details of an existing source, you must delete the source and then create it with the new configuration. 如果其他應用程式或元件使用現有的來源,建立新的來源與更新的組態,而不是刪除現有的來源。If other applications or components use the existing source, create a new source with the updated configuration instead of deleting the existing source.

您可以在您的事件類別目錄和訊息字串的當地語系化資源註冊事件來源。You can register the event source with localized resources for your event category and message strings. 您的應用程式可以使用資源識別碼,而不是指定實際的字串值寫入事件記錄檔項目。Your application can write event log entries by using resource identifiers instead of specifying the actual string values. 請參閱EventLogInstallerEventSourceCreationData類別,如需有關設定您的來源資源檔。Refer to the EventLogInstaller and EventSourceCreationData classes for more information about configuring your source with resource files.

如果您的應用程式會將字串值,直接寫入事件記錄檔,您不必設定資源的來源檔案內容。If your application writes string values directly to the event log, you do not have to set the resource file properties for the source. 寫入當地語系化的項目或寫入的直接存取的字串,則必須設定的來源。The source must be configured either for writing localized entries or for writing direct strings. 如果您的應用程式將使用的資源識別元和字串值的項目寫入,您必須註冊兩個不同的來源。If your application writes entries using both resource identifiers and string values, you must register two separate sources. 比方說,使用資源檔,設定一個來源,然後使用該來源中的WriteEvent方法寫入事件記錄檔的資源識別項的項目。For example, configure one source with resource files, and then use that source in the WriteEvent method to write entries using resource identifiers to the event log. 然後建立不同的來源,如果沒有資源檔,並使用該來源中的WriteEntry方法,將使用該來源的事件記錄檔中直接寫入字串。Then create a different source without resource files, and use that source in the WriteEntry method to write strings directly to the event log using that source.

當寫入事件時,您至少必須指定的訊息字串或將訊息字串的資源識別項。When writing events, you must at least specify either a message string or the resource identifier for a message string. 其他事件屬性是選擇性的。Other event properties are optional. 選擇性的事件設定的範例包括下列各項:Examples of optional event settings include the following:

  • 您可以設定EventLogEntryType來指定 事件檢視器顯示之項目的圖示。You can set the EventLogEntryType to specify the icon that the Event Viewer displays for the entry.

  • 如果您的應用程式會使用分類來篩選事件,您可以指定事件的類別識別項。You can specify a category identifier for the event, if your application uses categories for filtering the events.

  • 如果您想要指定的事件相關聯的其他資訊,您可以將二進位資料附加至您的事件項目中。You can attach binary data to your event entry if you want to associate additional information with a given event.

重要

事件記錄會消耗磁碟空間、 處理器時間,以及其他系統資源。Event logging consumes disk space, processor time, and other system resources. 請務必記錄必要的資訊。It is important to log only essential information. 我們建議您將事件記錄檔呼叫放在錯誤路徑,而不是在主要程式碼路徑中,因此它們不效能產生負面影響。We recommend that you place event log calls in an error path, rather than in the main code path, so they don't adversely affect performance.

如需執行個體的初始屬性值的清單EventLog,請參閱EventLog建構函式。For a list of initial property values for an instance of EventLog, see the EventLog constructor.

建構函式

EventLog() EventLog() EventLog() EventLog()

初始化 EventLog 類別的新執行個體。Initializes a new instance of the EventLog class. 不讓執行個體和任何記錄檔產生關聯。Does not associate the instance with any log.

EventLog(String) EventLog(String) EventLog(String) EventLog(String)

初始化 EventLog 類別的新執行個體。Initializes a new instance of the EventLog class. 讓執行個體與本機電腦上的記錄檔產生關聯。Associates the instance with a log on the local computer.

EventLog(String, String) EventLog(String, String) EventLog(String, String) EventLog(String, String)

初始化 EventLog 類別的新執行個體。Initializes a new instance of the EventLog class. 讓執行個體與指定電腦上的記錄檔產生關聯。Associates the instance with a log on the specified computer.

EventLog(String, String, String) EventLog(String, String, String) EventLog(String, String, String) EventLog(String, String, String)

初始化 EventLog 類別的新執行個體。Initializes a new instance of the EventLog class. 讓執行個體和指定電腦上的記錄檔產生關聯,並建立或指派指定的來源給 EventLogAssociates the instance with a log on the specified computer and creates or assigns the specified source to the EventLog.

屬性

CanRaiseEvents CanRaiseEvents CanRaiseEvents CanRaiseEvents

取得值,指出元件是否能引發事件。Gets a value indicating whether the component can raise an event.

(Inherited from Component)
Container Container Container Container

取得包含 IContainerComponentGets the IContainer that contains the Component.

(Inherited from Component)
DesignMode DesignMode DesignMode DesignMode

取得值,指出 Component 目前是否處於設計模式。Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
EnableRaisingEvents EnableRaisingEvents EnableRaisingEvents EnableRaisingEvents

取得或設定值,表示 EventLog 是否接收 EntryWritten 事件通知。Gets or sets a value indicating whether the EventLog receives EntryWritten event notifications.

Entries Entries Entries Entries

取得事件記錄檔的內容。Gets the contents of the event log.

Events Events Events Events

取得附加在這個 Component 上的事件處理常式清單。Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
Log Log Log Log

取得或設定要讀取或寫入的事件記錄檔的名稱。Gets or sets the name of the log to read from or write to.

LogDisplayName LogDisplayName LogDisplayName LogDisplayName

取得事件記錄檔的易記名稱。Gets the event log's friendly name.

MachineName MachineName MachineName MachineName

取得或設定要在其上讀取或寫入事件的電腦的名稱。Gets or sets the name of the computer on which to read or write events.

MaximumKilobytes MaximumKilobytes MaximumKilobytes MaximumKilobytes

取得或設定最大事件記錄檔大小 (以 KB 為單位)。Gets or sets the maximum event log size in kilobytes.

MinimumRetentionDays MinimumRetentionDays MinimumRetentionDays MinimumRetentionDays

取得事件記錄檔項目的保留天數。Gets the number of days to retain entries in the event log.

OverflowAction OverflowAction OverflowAction OverflowAction

當事件記錄檔到達最大記錄檔大小時,取得儲存新項目的已設定行為。Gets the configured behavior for storing new entries when the event log reaches its maximum log file size.

Site Site Site Site

取得或設定 ComponentISiteGets or sets the ISite of the Component.

(Inherited from Component)
Source Source Source Source

取得或設定寫入至事件記錄檔時登錄和使用的來源名稱。Gets or sets the source name to register and use when writing to the event log.

SynchronizingObject SynchronizingObject SynchronizingObject SynchronizingObject

取得或設定物件,其用於封送處理 (Marshal) 因為 EventLog 項目寫入事件而發出的事件處理常式呼叫。Gets or sets the object used to marshal the event handler calls issued as a result of an EventLog entry written event.

方法

BeginInit() BeginInit() BeginInit() BeginInit()

開始初始化表單或為另一個元件所使用的 EventLogBegins the initialization of an EventLog used on a form or used by another component. 初始化會於執行階段時執行。The initialization occurs at runtime.

Clear() Clear() Clear() Clear()

移除事件記錄檔的所有項目。Removes all entries from the event log.

Close() Close() Close() Close()

關閉事件記錄檔,並釋放讀取和寫入控制代碼。Closes the event log and releases read and write handles.

CreateEventSource(EventSourceCreationData) CreateEventSource(EventSourceCreationData) CreateEventSource(EventSourceCreationData) CreateEventSource(EventSourceCreationData)

使用事件來源及對應的事件記錄檔指定的組態屬性,建立有效的事件來源,以撰寫當地語系化的事件訊息。Establishes a valid event source for writing localized event messages, using the specified configuration properties for the event source and the corresponding event log.

CreateEventSource(String, String) CreateEventSource(String, String) CreateEventSource(String, String) CreateEventSource(String, String)

建立指定的來源名稱做為有效的事件來源,以便將項目寫入本機電腦上的記錄檔。Establishes the specified source name as a valid event source for writing entries to a log on the local computer. 這個方法也可以在本機電腦上建立新的自訂記錄檔。This method can also create a new custom log on the local computer.

CreateEventSource(String, String, String) CreateEventSource(String, String, String) CreateEventSource(String, String, String) CreateEventSource(String, String, String)

建立指定的來源名稱做為有效的事件來源,以便將項目寫入指定之電腦上的記錄檔。Establishes the specified source name as a valid event source for writing entries to a log on the specified computer. 這個方法也可以用來在指定的電腦上建立新的自訂記錄檔。This method can also be used to create a new custom log on the specified computer.

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Delete(String) Delete(String) Delete(String) Delete(String)

將事件記錄檔從本機電腦移除。Removes an event log from the local computer.

Delete(String, String) Delete(String, String) Delete(String, String) Delete(String, String)

將事件記錄檔從指定的電腦移除。Removes an event log from the specified computer.

DeleteEventSource(String) DeleteEventSource(String) DeleteEventSource(String) DeleteEventSource(String)

將事件來源登錄從本機電腦的事件記錄檔移除。Removes the event source registration from the event log of the local computer.

DeleteEventSource(String, String) DeleteEventSource(String, String) DeleteEventSource(String, String) DeleteEventSource(String, String)

將應用程式的事件來源登錄從指定的電腦移除。Removes the application's event source registration from the specified computer.

Dispose() Dispose() Dispose() Dispose()

釋放 Component 所使用的所有資源。Releases all resources used by the Component.

(Inherited from Component)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

釋放 EventLog 所使用的 Unmanaged 資源,並選擇性釋放 Managed 資源。Releases the unmanaged resources used by the EventLog, and optionally releases the managed resources.

EndInit() EndInit() EndInit() EndInit()

結束對表單或為另一個元件所使用之 EventLog 的初始化。Ends the initialization of an EventLog used on a form or by another component. 初始化會於執行階段時執行。The initialization occurs at runtime.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
Exists(String) Exists(String) Exists(String) Exists(String)

判斷記錄檔是否存在於本機電腦上。Determines whether the log exists on the local computer.

Exists(String, String) Exists(String, String) Exists(String, String) Exists(String, String)

判斷記錄檔是否存在於指定的電腦上。Determines whether the log exists on the specified computer.

GetEventLogs() GetEventLogs() GetEventLogs() GetEventLogs()

搜尋本機電腦上的所有事件記錄檔,並建立含有清單的 EventLog 物件陣列。Searches for all event logs on the local computer and creates an array of EventLog objects that contain the list.

GetEventLogs(String) GetEventLogs(String) GetEventLogs(String) GetEventLogs(String)

搜尋指定電腦上的所有事件記錄檔,並建立含有清單的 EventLog 物件陣列。Searches for all event logs on the given computer and creates an array of EventLog objects that contain the list.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetService(Type) GetService(Type) GetService(Type) GetService(Type)

傳回表示 Component 或其 Container 所提供之服務的物件。Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

取得存留期服務物件,以控制這個執行個體的存留期原則。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
LogNameFromSourceName(String, String) LogNameFromSourceName(String, String) LogNameFromSourceName(String, String) LogNameFromSourceName(String, String)

取得登錄指定來源的記錄檔的名稱。Gets the name of the log to which the specified source is registered.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
ModifyOverflowPolicy(OverflowAction, Int32) ModifyOverflowPolicy(OverflowAction, Int32) ModifyOverflowPolicy(OverflowAction, Int32) ModifyOverflowPolicy(OverflowAction, Int32)

當事件記錄檔到達最大檔案大小時,變更寫入新項目的已設定行為。Changes the configured behavior for writing new entries when the event log reaches its maximum file size.

RegisterDisplayName(String, Int64) RegisterDisplayName(String, Int64) RegisterDisplayName(String, Int64) RegisterDisplayName(String, Int64)

指定事件記錄檔的當地語系化名稱,這會顯示在伺服器的 [事件檢視器] 中。Specifies the localized name of the event log, which is displayed in the server Event Viewer.

SourceExists(String) SourceExists(String) SourceExists(String) SourceExists(String)

判斷事件來源是否登錄於本機電腦上。Determines whether an event source is registered on the local computer.

SourceExists(String, String) SourceExists(String, String) SourceExists(String, String) SourceExists(String, String)

判斷事件來源是否登錄於指定的電腦上。Determines whether an event source is registered on a specified computer.

ToString() ToString() ToString() ToString()

傳回任何包含 Component 名稱的 StringReturns a String containing the name of the Component, if any. 不應覆寫此方法。This method should not be overridden.

(Inherited from Component)
WriteEntry(String) WriteEntry(String) WriteEntry(String) WriteEntry(String)

將具有指定訊息文字的資訊類型項目寫入事件記錄檔。Writes an information type entry, with the given message text, to the event log.

WriteEntry(String, EventLogEntryType) WriteEntry(String, EventLogEntryType) WriteEntry(String, EventLogEntryType) WriteEntry(String, EventLogEntryType)

將具有指定訊息文字的錯誤、警告、資訊、成功稽核或失敗稽核項目寫入事件記錄檔。Writes an error, warning, information, success audit, or failure audit entry with the given message text to the event log.

WriteEntry(String, EventLogEntryType, Int32) WriteEntry(String, EventLogEntryType, Int32) WriteEntry(String, EventLogEntryType, Int32) WriteEntry(String, EventLogEntryType, Int32)

將有指定訊息文字和應用程式定義的事件識別項的項目寫入事件記錄檔。Writes an entry with the given message text and application-defined event identifier to the event log.

WriteEntry(String, EventLogEntryType, Int32, Int16) WriteEntry(String, EventLogEntryType, Int32, Int16) WriteEntry(String, EventLogEntryType, Int32, Int16) WriteEntry(String, EventLogEntryType, Int32, Int16)

將具有指定訊息文字、應用程式定義的事件識別項和應用程式定義的分類的項目寫入事件記錄檔。Writes an entry with the given message text, application-defined event identifier, and application-defined category to the event log.

WriteEntry(String, EventLogEntryType, Int32, Int16, Byte[]) WriteEntry(String, EventLogEntryType, Int32, Int16, Byte[]) WriteEntry(String, EventLogEntryType, Int32, Int16, Byte[]) WriteEntry(String, EventLogEntryType, Int32, Int16, Byte[])

將有指定訊息文字、應用程式定義的事件識別項和應用程式定義的分類的項目寫入事件記錄檔,並將二進位資料附加到訊息。Writes an entry with the given message text, application-defined event identifier, and application-defined category to the event log, and appends binary data to the message.

WriteEntry(String, String) WriteEntry(String, String) WriteEntry(String, String) WriteEntry(String, String)

使用指定的登錄事件來源,將具有指定訊息文字的資訊類型項目寫入事件記錄檔。Writes an information type entry with the given message text to the event log, using the specified registered event source.

WriteEntry(String, String, EventLogEntryType) WriteEntry(String, String, EventLogEntryType) WriteEntry(String, String, EventLogEntryType) WriteEntry(String, String, EventLogEntryType)

用指定的登錄事件來源,將有指定訊息文字的錯誤、警告、資訊、成功稽核或失敗稽核項目寫入事件記錄檔。Writes an error, warning, information, success audit, or failure audit entry with the given message text to the event log, using the specified registered event source.

WriteEntry(String, String, EventLogEntryType, Int32) WriteEntry(String, String, EventLogEntryType, Int32) WriteEntry(String, String, EventLogEntryType, Int32) WriteEntry(String, String, EventLogEntryType, Int32)

使用指定的登錄事件來源,將有指定訊息文字和應用程式定義的事件識別項的項目寫入事件記錄檔。Writes an entry with the given message text and application-defined event identifier to the event log, using the specified registered event source.

WriteEntry(String, String, EventLogEntryType, Int32, Int16) WriteEntry(String, String, EventLogEntryType, Int32, Int16) WriteEntry(String, String, EventLogEntryType, Int32, Int16) WriteEntry(String, String, EventLogEntryType, Int32, Int16)

使用指定的登錄事件來源,將有指定訊息文字、應用程式定義的事件識別項和應用程式定義的分類的項目寫入事件記錄檔。Writes an entry with the given message text, application-defined event identifier, and application-defined category to the event log, using the specified registered event source. category 可以讓事件檢視器用來篩選記錄檔中的事件。The category can be used by the Event Viewer to filter events in the log.

WriteEntry(String, String, EventLogEntryType, Int32, Int16, Byte[]) WriteEntry(String, String, EventLogEntryType, Int32, Int16, Byte[]) WriteEntry(String, String, EventLogEntryType, Int32, Int16, Byte[]) WriteEntry(String, String, EventLogEntryType, Int32, Int16, Byte[])

將有指定訊息文字、應用程式定義的事件識別項和應用程式定義的分類的項目寫入事件記錄檔 (使用指定的登錄事件來源),並將二進位資料附加到訊息。Writes an entry with the given message text, application-defined event identifier, and application-defined category to the event log (using the specified registered event source) and appends binary data to the message.

WriteEvent(EventInstance, Byte[], Object[]) WriteEvent(EventInstance, Byte[], Object[]) WriteEvent(EventInstance, Byte[], Object[]) WriteEvent(EventInstance, Byte[], Object[])

以指定的事件資料、訊息取代字串和相關聯的二進位資料來寫入事件記錄檔項目。Writes an event log entry with the given event data, message replacement strings, and associated binary data.

WriteEvent(EventInstance, Object[]) WriteEvent(EventInstance, Object[]) WriteEvent(EventInstance, Object[]) WriteEvent(EventInstance, Object[])

將當地語系化的項目寫入事件記錄檔。Writes a localized entry to the event log.

WriteEvent(String, EventInstance, Byte[], Object[]) WriteEvent(String, EventInstance, Byte[], Object[]) WriteEvent(String, EventInstance, Byte[], Object[]) WriteEvent(String, EventInstance, Byte[], Object[])

以指定的事件資料、訊息取代字串和相關聯的二進位資料,以及使用指定的已登錄事件來源,寫入事件記錄檔項目。Writes an event log entry with the given event data, message replacement strings, and associated binary data, and using the specified registered event source.

WriteEvent(String, EventInstance, Object[]) WriteEvent(String, EventInstance, Object[]) WriteEvent(String, EventInstance, Object[]) WriteEvent(String, EventInstance, Object[])

以指定的事件資料、訊息取代字串,以及使用指定的已登錄事件來源,寫入事件記錄檔項目。Writes an event log entry with the given event data and message replacement strings, using the specified registered event source.

事件

Disposed Disposed Disposed Disposed

當此元件由 Dispose() 方法的呼叫處置時發生。Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)
EntryWritten EntryWritten EntryWritten EntryWritten

發生於項目寫入至本機電腦上的事件記錄檔時。Occurs when an entry is written to an event log on the local computer.

適用於

另請參閱