EventLog 類別

定義

提供與 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.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
End Class

備註

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. 若要直接處置型別,請呼叫其 try/catch 區塊中的 Dispose 方法。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. 您可以使用 EventLogstatic 成員刪除記錄、取得記錄清單、建立或刪除來源,或判斷電腦是否已包含特定來源。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 需要 .NET Framework 2.0 和更新版本中特定動作的 EventLogPermission 許可權,或 .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 開始,使用者沒有存取安全性記錄檔的許可權;因此,會擲回 SecurityExceptionStarting 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 類別的新執行個體。Initializes a new instance of the EventLog class. 不讓執行個體和任何記錄檔產生關聯。Does not associate the instance with any log.

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 類別的新執行個體。Initializes a new instance of the EventLog class. 讓執行個體與指定電腦上的記錄檔產生關聯。Associates the instance with a log on the specified computer.

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

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

(繼承來源 Component)
Container

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

(繼承來源 Component)
DesignMode

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

(繼承來源 Component)
EnableRaisingEvents

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

Entries

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

Events

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

(繼承來源 Component)
Log

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

LogDisplayName

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

MachineName

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

MaximumKilobytes

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

MinimumRetentionDays

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

OverflowAction

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

Site

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

(繼承來源 Component)
Source

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

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()

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

Clear()

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

Close()

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

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)

建立指定的來源名稱做為有效的事件來源,以便將項目寫入本機電腦上的記錄檔。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)

建立指定的來源名稱做為有效的事件來源,以便將項目寫入指定之電腦上的記錄檔。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)

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

(繼承來源 MarshalByRefObject)
Delete(String)

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

Delete(String, String)

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

DeleteEventSource(String)

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

DeleteEventSource(String, String)

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

Dispose()

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

(繼承來源 Component)
Dispose(Boolean)

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

EndInit()

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

Equals(Object)

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

(繼承來源 Object)
Exists(String)

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

Exists(String, String)

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

GetEventLogs()

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

GetEventLogs(String)

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

GetHashCode()

作為預設雜湊函數。Serves as the default hash function.

(繼承來源 Object)
GetLifetimeService()

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

(繼承來源 MarshalByRefObject)
GetService(Type)

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

(繼承來源 Component)
GetType()

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

(繼承來源 Object)
InitializeLifetimeService()

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

(繼承來源 MarshalByRefObject)
LogNameFromSourceName(String, String)

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

MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
MemberwiseClone(Boolean)

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

(繼承來源 MarshalByRefObject)
ModifyOverflowPolicy(OverflowAction, Int32)

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

RegisterDisplayName(String, Int64)

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

SourceExists(String)

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

SourceExists(String, String)

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

ToString()

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

(繼承來源 Component)
WriteEntry(String)

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

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)

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

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[])

將有指定訊息文字、應用程式定義的事件識別項和應用程式定義的分類的項目寫入事件記錄檔,並將二進位資料附加到訊息。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)

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

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)

使用指定的登錄事件來源,將有指定訊息文字和應用程式定義的事件識別項的項目寫入事件記錄檔。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)

使用指定的登錄事件來源,將有指定訊息文字、應用程式定義的事件識別項和應用程式定義的分類的項目寫入事件記錄檔。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[])

將有指定訊息文字、應用程式定義的事件識別項和應用程式定義的分類的項目寫入事件記錄檔 (使用指定的登錄事件來源),並將二進位資料附加到訊息。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[])

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

WriteEvent(EventInstance, Object[])

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

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[])

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

事件

Disposed

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

(繼承來源 Component)
EntryWritten

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

適用於

另請參閱