EventLogEntry.EntryType 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取该项的事件类型。
public:
property System::Diagnostics::EventLogEntryType EntryType { System::Diagnostics::EventLogEntryType get(); };
public System.Diagnostics.EventLogEntryType EntryType { get; }
member this.EntryType : System.Diagnostics.EventLogEntryType
Public ReadOnly Property EntryType As EventLogEntryType
属性值
与事件日志中的项相关联的事件类型。
示例
下面的代码示例演示如何使用 EntryType 属性。 在此示例中,语句 switch
使用控制台输入来搜索指定 EntryType的事件日志条目。 如果找到匹配项,则控制台中会显示日志条目源信息。
#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
注解
所有事件类型都具有定义完善的通用数据,并且可以选择性地包含特定于事件的数据。 每个事件都是一种类型,应用程序在报告事件时会指示该类型。 事件查看器使用 事件类型来确定在事件日志的列表视图中显示哪个图标。