エントリのイベントの種類を取得します。
Public ReadOnly Property EntryType As EventLogEntryType
[C#]
public EventLogEntryType EntryType {get;}
[C++]
public: __property EventLogEntryType get_EntryType();
[JScript]
public function get EntryType() : EventLogEntryType;
プロパティ値
イベント ログのエントリに関連付けられているイベントの種類を示す EventLogEntryType 。通常、これはイベント ログ エントリの重大度レベルを示すために使用されます。
解説
すべての種類のイベントには十分に定義された共通データがあり、オプションとしてイベント固有のデータを格納できます。各イベントは単一の種類からなり、アプリケーションがそのイベントをレポートするときに種類が示されます。イベント ビューアは、イベントの種類に応じたアイコンを、イベント ログのリスト ビューに表示します。これは、エントリの重大度レベルを示します。
使用例
Imports System
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 -1 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 i
End Sub 'Main
End Class 'MyEventlogClass
[C#]
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>0;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;
}
}
}
}
[C++]
#using <mscorlib.dll>
#using <System.dll>
using namespace System;
using namespace System::Diagnostics;
void main() {
String* myEventType = 0;
// Associate the instance of 'EventLog' with local System Log.
EventLog* myEventLog = new EventLog(S"System", S".");
Console::WriteLine(S"1:Error");
Console::WriteLine(S"2:Information");
Console::WriteLine(S"3:Warning");
Console::WriteLine(S"Select the Event Type");
int myOption=Convert::ToInt32(Console::ReadLine());
switch (myOption) {
case 1: myEventType=S"Error";
break;
case 2: myEventType=S"Information";
break;
case 3: myEventType=S"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>0; i--) {
EventLogEntry* myLogEntry = myLogEntryCollection->Item[i];
// Select the entry having desired EventType.
if (__box(myLogEntry->EntryType)->Equals(myEventType)) {
// Display Source of the event.
Console::WriteLine(S"{0} was the source of last event of type {1}",
myLogEntry->Source, __box(myLogEntry->EntryType));
return;
}
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows NT Server 4.0, Windows NT Workstation 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
EventLogEntry クラス | EventLogEntry メンバ | System.Diagnostics 名前空間 | CategoryNumber | EventLogEntryType