EventLogEntry クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
イベント ログに 1 つのレコードをカプセル化します。 このクラスは継承できません。
public ref class EventLogEntry sealed : System::ComponentModel::Component, System::Runtime::Serialization::ISerializable
[System.Serializable]
public sealed class EventLogEntry : System.ComponentModel.Component, System.Runtime.Serialization.ISerializable
[<System.Serializable>]
type EventLogEntry = class
inherit Component
interface ISerializable
Public NotInheritable Class EventLogEntry
Inherits Component
Implements ISerializable
- 継承
- 属性
- 実装
例
次のコード例は、 EventLogEntry クラスの使用方法を示しています。 この例では、 switch ステートメントはコンソール入力を使用して、指定したイベントの種類のイベント ログ エントリを検索します。 一致するものが見つかった場合は、ログエントリのソース情報がコンソールに表示されます。
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のインスタンスを直接作成しません。 EventLog クラスのEntries メンバーには、EventLogEntry インスタンスのコレクションが含まれています。このコレクションは、EventLogEntryCollection.Item[] クラスのインデックス メンバーを使用して読み取るときに反復処理します。
Important
この型は、IDisposable インターフェイスを実装します。 型の使用が完了したら、直接または間接的に破棄する必要があります。 型を直接破棄するには、Disposetry/ ブロックでその catch メソッドを呼び出します。 間接的に破棄するには、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) |
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() |
Stringの名前 (存在する場合) を含むComponentを返します。 このメソッドはオーバーライドしないでください。 (継承元 Component) |
イベント
| 名前 | 説明 |
|---|---|
| Disposed |
コンポーネントが Dispose() メソッドの呼び出しによって破棄されるときに発生します。 (継承元 Component) |
明示的なインターフェイスの実装
| 名前 | 説明 |
|---|---|
| ISerializable.GetObjectData(SerializationInfo, StreamingContext) |
ターゲット オブジェクトをシリアル化するために必要なデータを SerializationInfo に設定します。 |