EventLogEntry 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在事件日志中封装单个记录。 此类不能被继承。
public ref class EventLogEntry sealed : System::ComponentModel::Component, System::Runtime::Serialization::ISerializablepublic sealed class EventLogEntry : System.ComponentModel.Component, System.Runtime.Serialization.ISerializable[System.Serializable]
public sealed class EventLogEntry : System.ComponentModel.Component, System.Runtime.Serialization.ISerializabletype EventLogEntry = class
    inherit Component
    interface ISerializable[<System.Serializable>]
type EventLogEntry = class
    inherit Component
    interface ISerializablePublic NotInheritable Class EventLogEntry
Inherits Component
Implements ISerializable- 继承
- 属性
- 实现
示例
下面的代码示例演示如何使用 EventLogEntry 类。 在此示例中,语句 switch 使用控制台输入来搜索指定事件类型的事件日志条目。  如果找到匹配项,则控制台中会显示日志条目源信息。
#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
注解
使用 类时,通常不会直接创建 的EventLog实例EventLogEntry。 Entries类的成员EventLog包含实例集合EventLogEntry,使用类索引成员进行读取时循环访问这些EventLogEntryCollection.Item[]实例。
重要
此类型实现 IDisposable 接口。 在使用完类型后,您应直接或间接释放类型。 若要直接释放类型,请在 try/catch 块中调用其 Dispose 方法。 若要间接释放类型,请使用 using(在 C# 中)或 Using(在 Visual Basic 中)等语言构造。 有关详细信息,请参阅 IDisposable 接口主题中的“使用实现 IDisposable 的对象”一节。
属性
| CanRaiseEvents | 获取一个指示组件是否可以引发事件的值。(继承自 Component) | 
| Category | 获取与该项的 CategoryNumber 属性关联的文本。 | 
| CategoryNumber | 获取事件日志项的类别号。 | 
| Container | 获取包含 IContainer 的 Component。(继承自 Component) | 
| Data | 获取与该项关联的二进制数据。 | 
| DesignMode | 获取一个值,用以指示 Component 当前是否处于设计模式。(继承自 Component) | 
| EntryType | 获取该项的事件类型。 | 
| EventID | 
				已过时.
			 
				已过时.
			 
				已过时.
			 获取当前事件项的应用程序特定事件标识符。 | 
| Events | 获取附加到此 Component 的事件处理程序的列表。(继承自 Component) | 
| Index | 获取该项在事件日志中的索引。 | 
| InstanceId | 获取指定事件项的消息文本的资源标识符。 | 
| MachineName | 获取在其上生成该项的计算机的名称。 | 
| Message | 获取与该事件项关联的本地化消息。 | 
| ReplacementStrings | 获取与事件日志项关联的替换字符串。 | 
| Site | (继承自 Component) | 
| Source | 获取生成该事件的应用程序的名称。 | 
| TimeGenerated | 获取生成该事件的本地时间。 | 
| TimeWritten | 获取在日志中写入该事件的本地时间。 | 
| UserName | 获取负责该事件的用户的名称。 | 
方法
| CreateObjRef(Type) | 创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。(继承自 MarshalByRefObject) | 
| Dispose() | 释放由 Component 使用的所有资源。(继承自 Component) | 
| Dispose(Boolean) | 释放由 Component 占用的非托管资源,还可以另外再释放托管资源。(继承自 Component) | 
| Equals(EventLogEntry) | 对两个事件日志项进行比较。 | 
| Equals(Object) | 确定指定对象是否等于当前对象。(继承自 Object) | 
| GetHashCode() | 作为默认哈希函数。(继承自 Object) | 
| GetLifetimeService() | 
		已过时.
	 检索控制此实例的生存期策略的当前生存期服务对象。(继承自 MarshalByRefObject) | 
| GetService(Type) | 返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。(继承自 Component) | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| InitializeLifetimeService() | 
		已过时.
	 获取生存期服务对象来控制此实例的生存期策略。(继承自 MarshalByRefObject) | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| MemberwiseClone(Boolean) | 创建当前 MarshalByRefObject 对象的浅表副本。(继承自 MarshalByRefObject) | 
| ToString() | 返回包含 Component 的名称的 String(如果有)。 不应重写此方法。(继承自 Component) | 
事件
| Disposed | 在通过调用 Dispose() 方法释放组件时发生。(继承自 Component) | 
显式接口实现
| ISerializable.GetObjectData(SerializationInfo, StreamingContext) | 使用将目标对象序列化所需的数据填充 SerializationInfo。 |