EventLog.Entries 屬性

定義

取得事件記錄檔的內容。

public:
 property System::Diagnostics::EventLogEntryCollection ^ Entries { System::Diagnostics::EventLogEntryCollection ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Diagnostics.EventLogEntryCollection Entries { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Entries : System.Diagnostics.EventLogEntryCollection
Public ReadOnly Property Entries As EventLogEntryCollection

屬性值

將項目保存在事件記錄檔中的 EventLogEntryCollection。 每個項目與 EventLogEntry 類別的執行個體相關聯。

屬性

範例

下列範例會在本機計算機上讀取事件記錄檔 「MyNewLog」 中的專案。

#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
int main()
{
   EventLog^ myLog = gcnew EventLog;
   myLog->Log = "MyNewLog";
   System::Collections::IEnumerator^ myEnum = myLog->Entries->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      EventLogEntry^ entry = safe_cast<EventLogEntry^>(myEnum->Current);
      Console::WriteLine( "\tEntry: {0}", entry->Message );
   }
}
using System;
using System.Diagnostics;

class MySample{

    public static void Main(){

        EventLog myLog = new EventLog();
        myLog.Log = "MyNewLog";
        foreach(EventLogEntry entry in myLog.Entries){
            Console.WriteLine("\tEntry: " + entry.Message);
        }
    }
}
Option Strict
Option Explicit

Imports System.Diagnostics

Class MySample
    Public Shared Sub Main()
        
        Dim myLog As New EventLog()
        myLog.Log = "MyNewLog"
        Dim entry As EventLogEntry
        For Each entry In  myLog.Entries
            Console.WriteLine((ControlChars.Tab & "Entry: " & entry.Message))
        Next entry
    End Sub
End Class

備註

從事件記錄檔讀取時, Entries 請使用 成員。

因為屬性是只讀的,所以您無法使用 Entries修改專案或寫入記錄檔。 請改為指定 Source 和呼叫 WriteEntry 以寫入新的記錄專案。 您可以使用 Entries 來計算事件記錄檔中的項目數目,並檢視 EventLogEntry 集合中的每個專案。 使用索引 Item[] 成員來擷取特定項目的相關信息,例如 MessageCategoryTimeWrittenEntryType

只有在從記錄檔讀取時,才不需要指定 Source 。 您只能 Log 指定實例的名稱和 MachineName (伺服器電腦名稱) 屬性 EventLog 。 不論是哪一種情況, Entries 成員都會自動填入事件記錄檔的專案清單。 您可以為此清單中的項目選取適當的索引,以讀取個別專案。

讀取和寫入記錄項目之間的重要差別在於,不需要明確呼叫讀取方法。 Log指定 和 MachineName 之後,Entries屬性會自動填入。 如果您變更 或 MachineName 屬性的值LogEntries則會在下一次讀取屬性時重新填入該屬性。

注意

如果您連線到記錄檔,則不需要指定 MachineName 。 如果您未指定 MachineName,則會假設本機計算機 “.”。

適用於

另請參閱