EventLogEntry クラス

定義

イベント ログの単一レコードをカプセル化します。 このクラスは継承できません。

public ref class EventLogEntry sealed : System::ComponentModel::Component, System::Runtime::Serialization::ISerializable
public sealed class EventLogEntry : System.ComponentModel.Component, System.Runtime.Serialization.ISerializable
[System.Serializable]
public sealed class EventLogEntry : System.ComponentModel.Component, System.Runtime.Serialization.ISerializable
type EventLogEntry = class
    inherit Component
    interface ISerializable
[<System.Serializable>]
type EventLogEntry = class
    inherit Component
    interface ISerializable
Public 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

注釈

通常は、クラスを操作するときに直接インスタンス EventLogEntryEventLog 作成しません。 クラスのEventLogメンバーにはインスタンスのEventLogEntryコレクションが含まれています。このコレクションはEntries、クラス インデックス メンバーを使用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

ComponentISite を取得または設定します。

(継承元 Component)
Source

このイベントを発生させたアプリケーションの名前を取得します。

TimeGenerated

このイベントが生成された現地時間を取得します。

TimeWritten

このイベントがログに書き込まれた現地時間を取得します。

UserName

このイベントを発生させたユーザーの名前を取得します。

メソッド

CreateObjRef(Type)

リモート オブジェクトとの通信に使用するプロキシの生成に必要な情報をすべて格納しているオブジェクトを作成します。

(継承元 MarshalByRefObject)
Dispose()

Component によって使用されているすべてのリソースを解放します。

(継承元 Component)
Dispose(Boolean)

Component によって使用されているアンマネージド リソースを解放し、オプションでマネージド リソースも解放します。

(継承元 Component)
Equals(EventLogEntry)

2 つのイベント ログ エントリを比較します。

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)

events

Disposed

Dispose() メソッドの呼び出しによってコンポーネントが破棄されるときに発生します。

(継承元 Component)

明示的なインターフェイスの実装

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

SerializationInfo に、オブジェクトをシリアル化するために必要なデータを設定します。

適用対象

こちらもご覧ください