EventLogEntryCollection クラス
EventLogEntry インスタンスのコレクションのサイズと列挙子を定義します。
この型のすべてのメンバの一覧については、EventLogEntryCollection メンバ を参照してください。
System.Object
System.Diagnostics.EventLogEntryCollection
Public Class EventLogEntryCollection
Implements ICollection, IEnumerable
[C#]
public class EventLogEntryCollection : ICollection, IEnumerable
[C++]
public __gc class EventLogEntryCollection : public ICollection,
IEnumerable
[JScript]
public class EventLogEntryCollection implements ICollection,
IEnumerable
スレッドセーフ
この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。
解説
EventLogEntryCollection クラスは、 EventLog インスタンスに関連付けられたエントリを読み取るときに使用します。 EventLog クラスの Entries プロパティは、イベント ログのすべてのエントリのコレクションです。
新しいエントリは既存のリストの末尾に追加されるため、コレクションを順に処理していけば、最初に EventLogEntryCollection を作成した後で作成されたエントリにもアクセスできます。ただし、リスト全体を参照した後では、リストは新しいエントリで更新されません。
使用例
Imports System
Imports System.Collections
Imports System.Diagnostics
Class EventLogEntryCollection_Item
Public Shared Sub Main()
Try
Dim myLogName As String = "MyNewlog"
' Check if the source exists.
If Not EventLog.SourceExists("MySource") Then
'Create source.
EventLog.CreateEventSource("MySource", myLogName)
Console.WriteLine("Creating EventSource")
' Get the EventLog associated if the source exists.
Else
myLogName = EventLog.LogNameFromSourceName("MySource", ".")
End If
' Create an EventLog instance and assign its source.
Dim myEventLog2 As New EventLog()
myEventLog2.Source = "MySource"
' Write an informational entry to the event log.
myEventLog2.WriteEntry("Successfully created a new Entry in the Log")
myEventLog2.Close()
' Create a new EventLog object.
Dim myEventLog1 As New EventLog()
myEventLog1.Log = myLogName
' Obtain the Log Entries of "MyNewLog".
Dim myEventLogEntryCollection As EventLogEntryCollection = myEventLog1.Entries
myEventLog1.Close()
Console.WriteLine("The number of entries in 'MyNewLog' = " + _
myEventLogEntryCollection.Count.ToString())
' Display the 'Message' property of EventLogEntry.
Dim i As Integer
For i = 0 To myEventLogEntryCollection.Count - 1
Console.WriteLine("The Message of the EventLog is :" + _
myEventLogEntryCollection(i).Message)
Next i
' Copy the EventLog entries to Array of type EventLogEntry.
Dim myEventLogEntryArray(myEventLogEntryCollection.Count-1) As EventLogEntry
myEventLogEntryCollection.CopyTo(myEventLogEntryArray, 0)
Dim myEnumerator As IEnumerator = myEventLogEntryArray.GetEnumerator()
While myEnumerator.MoveNext()
Dim myEventLogEntry As EventLogEntry = CType(myEnumerator.Current, EventLogEntry)
Console.WriteLine("The LocalTime the Event is generated is " + _
myEventLogEntry.TimeGenerated)
End While
Catch e As Exception
Console.WriteLine("Exception:{0}", e.Message.ToString())
End Try
End Sub 'Main
End Class 'EventLogEntryCollection_Item
[C#]
using System;
using System.Collections;
using System.Diagnostics;
class EventLogEntryCollection_Item
{
public static void Main()
{
try
{
string myLogName = "MyNewLog";
// Check if the source exists.
if(!EventLog.SourceExists("MySource"))
{
//Create source.
EventLog.CreateEventSource("MySource", myLogName);
Console.WriteLine("Creating EventSource");
}
else
// Get the EventLog associated if the source exists.
myLogName = EventLog.LogNameFromSourceName("MySource",".");
// Create an EventLog instance and assign its source.
EventLog myEventLog2 = new EventLog();
myEventLog2.Source = "MySource";
// Write an informational entry to the event log.
myEventLog2.WriteEntry("Successfully created a new Entry in the Log");
myEventLog2.Close();
// Create a new EventLog object.
EventLog myEventLog1 = new EventLog();
myEventLog1.Log = myLogName;
// Obtain the Log Entries of "MyNewLog".
EventLogEntryCollection myEventLogEntryCollection=
myEventLog1.Entries;
myEventLog1.Close();
Console.WriteLine("The number of entries in 'MyNewLog' = "
+myEventLogEntryCollection.Count);
// Display the 'Message' property of EventLogEntry.
for(int i=0;i<myEventLogEntryCollection.Count;i++)
{
Console.WriteLine("The Message of the EventLog is :"
+myEventLogEntryCollection[i].Message);
}
// Copy the EventLog entries to Array of type EventLogEntry.
EventLogEntry[] myEventLogEntryArray=
new EventLogEntry[myEventLogEntryCollection.Count];
myEventLogEntryCollection.CopyTo(myEventLogEntryArray,0);
IEnumerator myEnumerator=myEventLogEntryArray.GetEnumerator();
while(myEnumerator.MoveNext())
{
EventLogEntry myEventLogEntry =(EventLogEntry)myEnumerator.Current;
Console.WriteLine("The LocalTime the Event is generated is "
+myEventLogEntry.TimeGenerated);
}
}
catch(Exception e)
{
Console.WriteLine("Exception:{0}",e.Message);
}
}
}
[C++]
#using <mscorlib.dll>
#using <System.dll>
using namespace System;
using namespace System::Collections;
using namespace System::Diagnostics;
int main() {
try {
String* myLogName = S"MyNewLog";
// Check if the source exists.
if (!EventLog::SourceExists(S"MySource")) {
//Create source.
EventLog::CreateEventSource(S"MySource", myLogName);
Console::WriteLine(S"Creating EventSource");
} else
// Get the EventLog associated if the source exists.
myLogName = EventLog::LogNameFromSourceName(S"MySource", S".");
// Create an EventLog instance and assign its source.
EventLog* myEventLog2 = new EventLog();
myEventLog2->Source = S"MySource";
// Write an informational entry to the event log.
myEventLog2->WriteEntry(S"Successfully created a new Entry in the Log");
myEventLog2->Close();
// Create a new EventLog Object*.
EventLog* myEventLog1 = new EventLog();
myEventLog1->Log = myLogName;
// Obtain the Log Entries of S"MyNewLog".
EventLogEntryCollection* myEventLogEntryCollection =
myEventLog1->Entries;
myEventLog1->Close();
Console::WriteLine(S"The number of entries in 'MyNewLog' = {0}",
__box(myEventLogEntryCollection->Count));
// Display the 'Message' property of EventLogEntry.
for (int i=0;i<myEventLogEntryCollection->Count;i++) {
Console::WriteLine(S"The Message of the EventLog is : {0}",
myEventLogEntryCollection->Item[i]->Message);
}
// Copy the EventLog entries to Array of type EventLogEntry.
EventLogEntry* myEventLogEntryArray[] =
new EventLogEntry*[myEventLogEntryCollection->Count];
myEventLogEntryCollection->CopyTo(myEventLogEntryArray, 0);
IEnumerator* myEnumerator=myEventLogEntryArray->GetEnumerator();
while (myEnumerator->MoveNext()) {
EventLogEntry* myEventLogEntry =
__try_cast<EventLogEntry*>(myEnumerator->Current);
Console::WriteLine(S"The LocalTime the Event is generated is {0}",
__box(myEventLogEntry->TimeGenerated));
}
} catch (Exception* e) {
Console::WriteLine(S"Exception: {0}", e->Message);
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
名前空間: System.Diagnostics
プラットフォーム: Windows NT Server 4.0, Windows NT Workstation 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
アセンブリ: System (System.dll 内)
参照
EventLogEntryCollection メンバ | System.Diagnostics 名前空間 | EventLog | Entries