EventLog.Entries EventLog.Entries EventLog.Entries EventLog.Entries Property

定義

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

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

屬性值

將項目保存在事件記錄檔中的 EventLogEntryCollectionAn EventLogEntryCollection holding the entries in the event log. 每個項目與 EventLogEntry 類別的執行個體相關聯。Each entry is associated with an instance of the EventLogEntry class.

範例

下列範例會讀取本機電腦上事件記錄檔 "Mynewlog 清單" 中的專案。The following example reads entries in the event log, "MyNewLog", on the local computer.

#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 ' Main
End Class ' MySample

備註

從事件Entries記錄檔讀取時,請使用成員。Use the Entries member when reading from the event log.

因為屬性是唯讀的,所以您無法使用Entries修改專案或寫入記錄檔。Because the property is read-only, you cannot modify an entry or write to the log using Entries. 相反Source地,請指定並WriteEntry呼叫來寫入新的記錄專案。Instead, specify a Source and call WriteEntry to write a new log entry. 您可以使用Entries來計算事件記錄檔中的專案數,並在集合中EventLogEntry查看每個專案。You can use Entries to count the number of entries in the event log, and view each EventLogEntry in the collection. 使用已編制Item[Int32]索引的成員來抓取特定專案的相關資訊, Message例如CategoryTimeWritten、或EntryTypeUse the indexed Item[Int32] member to retrieve information about a specific entry, such as Message, Category, TimeWritten, or EntryType.

只有Source在從記錄檔讀取時,才需要指定。It is not necessary to specify a Source when only reading from a log. 您只能指定Log EventLog實例的名稱和MachineName (伺服器電腦名稱稱)屬性。You can specify only the Log name and MachineName (server computer name) properties for the EventLog instance. 不論是哪一種Entries情況,成員都會自動填入事件記錄檔的專案清單。In either case, the Entries member is automatically populated with the event log's list of entries. 您可以為此清單中的專案選取適當的索引,以讀取個別的專案。You can select the appropriate index for an item in this list to read individual entries.

讀取和寫入記錄檔專案之間的重要差異在於,不需要明確呼叫 read 方法。An important distinction between reading and writing log entries is that it is not necessary to explicitly call a read method. Log指定和MachineName之後,Entries會自動填入屬性。After the Log and MachineName are specified, the Entries property is automatically populated. 如果您變更LogMachineName屬性的值, Entries下一次讀取時,會重新擴充屬性。If you change the value of the Log or MachineName property, the Entries property is repopulated the next time you read it.

注意

MachineName如果您要連接到記錄檔,則不需要指定。You are not required to specify the MachineName if you are connecting to a log. 如果您未指定MachineName,則會假設為本機電腦 "."。If you do not specify the MachineName, the local computer, ".", is assumed.

安全性

EventLogPermission
用於管理電腦上的事件記錄檔資訊。for administering event log information on the computer. 相關聯的列舉:AdministerAssociated enumeration: Administer

適用於

另請參閱