EventLogEntry 類別

定義

將單一記錄封裝於事件記錄檔中。Encapsulates a single record in the event log. 此類別無法獲得繼承。This class cannot be inherited.

public ref class EventLogEntry sealed : System::ComponentModel::Component, System::Runtime::Serialization::ISerializable
public sealed class EventLogEntry : System.ComponentModel.Component, System.Runtime.Serialization.ISerializable
[System.Serializable]
public sealed class EventLogEntry : System.ComponentModel.Component, System.Runtime.Serialization.ISerializable
type EventLogEntry = class
    inherit Component
    interface ISerializable
[<System.Serializable>]
type EventLogEntry = class
    inherit Component
    interface ISerializable
Public NotInheritable Class EventLogEntry
Inherits Component
Implements ISerializable
繼承
屬性
實作

範例

下列程式碼範例將示範如何使用 EventLogEntry 類別。The following code example demonstrates the use of the EventLogEntry class. 在此範例中, switch 語句會使用主控台輸入來搜尋指定事件種類的事件記錄檔專案。In this example, a switch statement uses console input to search for event log entries for the specified event type. 如果找到相符專案,就會在主控台中顯示記錄專案來源資訊。If a match is found, log entry source information is displayed at the console.

#using <System.dll>

using namespace System;
using namespace System::Diagnostics;

int main()
{
   String^ myEventType = nullptr;
   
   // Associate the instance of 'EventLog' with local System Log.
   EventLog^ myEventLog = gcnew EventLog( "System","." );
   Console::WriteLine( "1:Error" );
   Console::WriteLine( "2:Information" );
   Console::WriteLine( "3:Warning" );
   Console::WriteLine( "Select the Event Type" );
   int myOption = Convert::ToInt32( Console::ReadLine() );
   switch ( myOption )
   {
      case 1:
         myEventType = "Error";
         break;

      case 2:
         myEventType = "Information";
         break;

      case 3:
         myEventType = "Warning";
         break;

      default:
         break;
   }
   EventLogEntryCollection^ myLogEntryCollection = myEventLog->Entries;
   int myCount = myLogEntryCollection->Count;
   
   // Iterate through all 'EventLogEntry' instances in 'EventLog'.
   for ( int i = myCount - 1; i > -1; i-- )
   {
      EventLogEntry^ myLogEntry = myLogEntryCollection[ i ];
      
      // Select the entry having desired EventType.
      if ( myLogEntry->EntryType.Equals( myEventType ) )
      {
         // Display Source of the event.
         Console::WriteLine( "{0} was the source of last event of type {1}", myLogEntry->Source, myLogEntry->EntryType );
         return 0;
      }
   }
}
using System;
using System.Diagnostics;
   class MyEventlogClass
   {
      public static void Main()
      {
         String myEventType=null;
         // Associate the instance of 'EventLog' with local System Log.
         EventLog myEventLog = new EventLog("System", ".");
         Console.WriteLine("1:Error");
         Console.WriteLine("2:Information");
         Console.WriteLine("3:Warning");
         Console.WriteLine("Select the Event Type");
         int myOption=Convert.ToInt32(Console.ReadLine());
         switch(myOption)
         {
            case 1:  myEventType="Error";
                     break;
            case 2:  myEventType="Information";
                     break;
            case 3:  myEventType="Warning";
                     break;
            default: break;
         }

            EventLogEntryCollection myLogEntryCollection=myEventLog.Entries;
            int myCount =myLogEntryCollection.Count;
            // Iterate through all 'EventLogEntry' instances in 'EventLog'.
            for(int i=myCount-1;i>-1;i--)
            {
               EventLogEntry myLogEntry = myLogEntryCollection[i];
               // Select the entry having desired EventType.
               if(myLogEntry.EntryType.ToString().Equals(myEventType))
               {
                  // Display Source of the event.
                  Console.WriteLine(myLogEntry.Source
                     +" was the source of last event of type "
                     +myLogEntry.EntryType);
                  return;
               }
            }
         }
   }
Imports System.Diagnostics

Class MyEventlogClass
   Public Shared Sub Main()
      Dim myEventType As String = Nothing
      ' Associate the instance of 'EventLog' with local System Log.
      Dim myEventLog As New EventLog("System", ".")
      Console.WriteLine("1:Error")
      Console.WriteLine("2:Information")
      Console.WriteLine("3:Warning")
      Console.WriteLine("Select the Event Type")
      Dim myOption As Integer = Convert.ToInt32(Console.ReadLine())
      Select Case myOption
         Case 1
            myEventType = "Error"
         Case 2
            myEventType = "Information"
         Case 3
            myEventType = "Warning"
         Case Else
      End Select

      Dim myLogEntryCollection As EventLogEntryCollection = myEventLog.Entries
      Dim myCount As Integer = myLogEntryCollection.Count
      ' Iterate through all 'EventLogEntry' instances in 'EventLog'.
      Dim i As Integer
      For i = myCount - 1 To 0 Step -1
         Dim myLogEntry As EventLogEntry = myLogEntryCollection(i)
         ' Select the entry having desired EventType.
         If myLogEntry.EntryType.ToString().Equals(myEventType) Then
            ' Display Source of the event.
            Console.WriteLine(myLogEntry.Source + " was the source of last "& _
                             "event of type " & myLogEntry.EntryType.ToString())
            Return
         End If
      Next 
   End Sub
End Class

備註

使用類別時,您通常不會直接建立的實例 EventLogEntry EventLogYou usually will not create instances of EventLogEntry directly when working with the EventLog class. Entries類別的成員 EventLog 包含實例的集合 EventLogEntry ,當您使用 EventLogEntryCollection.Item[] 類別索引成員進行讀取時,會逐一查看這些實例。The Entries member of the EventLog class contains a collection of EventLogEntry instances, which you iterate over when reading by using the EventLogEntryCollection.Item[] class index member.

重要

此型別代表 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.

屬性

CanRaiseEvents

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

(繼承來源 Component)
Category

取得與這個項目的 CategoryNumber 屬性相關聯的文字。Gets the text associated with the CategoryNumber property for this entry.

CategoryNumber

取得事件記錄檔項目的分類編號。Gets the category number of the event log entry.

Container

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

(繼承來源 Component)
Data

取得與項目相關聯的二進位資料。Gets the binary data associated with the entry.

DesignMode

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

(繼承來源 Component)
EntryType

取得這個項目的事件類型。Gets the event type of this entry.

EventID
已過時。
已過時。
已過時。

取得目前事件項目的應用程式特定事件識別項。Gets the application-specific event identifier for the current event entry.

Events

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

(繼承來源 Component)
Index

取得事件記錄檔中這個項目的索引。Gets the index of this entry in the event log.

InstanceId

取得資源識別項,指定事件項目的訊息文字。Gets the resource identifier that designates the message text of the event entry.

MachineName

取得產生這個項目的電腦名稱。Gets the name of the computer on which this entry was generated.

Message

取得與這個事件項目相關聯的當地語系化訊息。Gets the localized message associated with this event entry.

ReplacementStrings

取得與事件記錄檔項目相關聯的取代字串。Gets the replacement strings associated with the event log entry.

Site

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

(繼承來源 Component)
Source

取得產生這個事件的應用程式名稱。Gets the name of the application that generated this event.

TimeGenerated

取得產生這個事件的當地時間。Gets the local time at which this event was generated.

TimeWritten

取得將這個事件寫入至記錄檔的當地時間。Gets the local time at which this event was written to the log.

UserName

取得為這個事件負責的使用者名稱。Gets the name of the user who is responsible for this event.

方法

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

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

(繼承來源 Component)
Dispose(Boolean)

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

(繼承來源 Component)
Equals(EventLogEntry)

在兩個事件記錄檔項目之間進行比較。Performs a comparison between two event log entries.

Equals(Object)

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

(繼承來源 Object)
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)
MemberwiseClone()

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

(繼承來源 Object)
MemberwiseClone(Boolean)

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

(繼承來源 MarshalByRefObject)
ToString()

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

(繼承來源 Component)

事件

Disposed

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

(繼承來源 Component)

明確介面實作

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

將序列化目標物件所需的資料填入 SerializationInfoPopulates a SerializationInfo with the data needed to serialize the target object.

適用於

另請參閱