EventLogEntry 类
在事件日志中封装单个记录。无法继承此类。
**命名空间:**System.Diagnostics
**程序集:**System(在 system.dll 中)
语法
声明
<SerializableAttribute> _
Public NotInheritable Class EventLogEntry
Inherits Component
Implements ISerializable
用法
Dim instance As EventLogEntry
[SerializableAttribute]
public sealed class EventLogEntry : Component, ISerializable
[SerializableAttribute]
public ref class EventLogEntry sealed : public Component, ISerializable
/** @attribute SerializableAttribute() */
public final class EventLogEntry extends Component implements ISerializable
SerializableAttribute
public final class EventLogEntry extends Component implements ISerializable
备注
当使用 EventLog 类时,通常不会直接创建 EventLogEntry 的实例。EventLog 类的 Entries 成员包含 EventLogEntry 实例的集合,当使用 EventLogEntryCollection.Item 类索引成员进行读取时,将循环访问该集合。
Windows 98, Windows Millennium Edition 平台说明: Windows 98/Windows Millennium 不支持事件日志。
示例
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
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;
}
}
}
}
#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 > 0; 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;
}
}
}
import System.*;
import System.Diagnostics.*;
class MyEventlogClass
{
public static void main(String[] args)
{
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.get_Entries();
int myCount = myLogEntryCollection.get_Count();
// Iterate through all 'EventLogEntry' instances in 'EventLog'.
for (int i = myCount - 1; i > 0; i--) {
EventLogEntry myLogEntry = myLogEntryCollection.get_Item(i);
// Select the entry having desired EventType.
if (myLogEntry.get_EntryType().ToString().Equals(myEventType)) {
// Display Source of the event.
Console.WriteLine(myLogEntry.get_Source()
+ " was the source of last event of type "
+ myLogEntry.get_EntryType());
return;
}
}
} //main
} //MyEventlogClass
继承层次结构
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Diagnostics.EventLogEntry
线程安全
此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。
平台
Windows 98、Windows 2000 SP4、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
请参见
参考
EventLogEntry 成员
System.Diagnostics 命名空间
EventLog 类
EventLogEntryCollection
EventInstance 类