EntryWrittenEventArgs コンストラクタ (EventLogEntry)
アセンブリ: System (system.dll 内)
構文
使用例
EntryWrittenEventArgs コンストラクタの例を次に示します。これは、カスタム EventLog オブジェクトを作成して、エントリを書き込みます。次に、カスタム EventLog 内の最初のエントリを使用して EntryWrittenEventArgs オブジェクトを作成します。このオブジェクトは、メッセージを通知するときに使用します。
Imports System Imports System.Diagnostics Class MySample Public Shared Sub Main() Try Dim myNewLog As New EventLog() ' Create the source if it does not exist already. If Not EventLog.SourceExists("MySource") Then EventLog.CreateEventSource("MySource", "MyNewLog") Console.WriteLine("CreatingEventSource") End If myNewLog.Log = "MyNewLog" myNewLog.Source = "MySource" ' Write an entry to the EventLog. myNewLog.WriteEntry("The Latest entry in the Event Log") Dim myEntries As Integer = myNewLog.Entries.Count Dim entry As EventLogEntry = myNewLog.Entries(myEntries - 1) Dim myEntryEventArgs As New EntryWrittenEventArgs(entry) MyOnEntry(myNewLog, myEntryEventArgs) Catch e As Exception Console.WriteLine("Exception Raised" + e.Message) End Try End Sub 'Main Protected Shared Sub MyOnEntry(source As Object, e As EntryWrittenEventArgs) Dim myEventLogEntry As EventLogEntry = e.Entry If Not (myEventLogEntry Is Nothing) Then Console.WriteLine("Current message entry is: '" + _ myEventLogEntry.Message + "'") Else Console.WriteLine("The current entry is null") End If End Sub 'MyOnEntry End Class 'MySample
using System; using System.Diagnostics; class MySample { public static void Main() { try { EventLog myNewLog = new EventLog(); myNewLog.Log = "MyNewLog"; myNewLog.Source="MySource"; // Create the source if it does not exist already. if(!EventLog.SourceExists("MySource")) { EventLog.CreateEventSource("MySource", "MyNewLog"); Console.WriteLine("CreatingEventSource"); } // Write an entry to the EventLog. myNewLog.WriteEntry("The Latest entry in the Event Log"); int myEntries = myNewLog.Entries.Count; EventLogEntry entry =myNewLog.Entries[myEntries-1]; EntryWrittenEventArgs myEntryEventArgs= new EntryWrittenEventArgs(entry); MyOnEntry(myNewLog,myEntryEventArgs); } catch(Exception e) { Console.WriteLine("Exception Raised" +e.Message); } } protected static void MyOnEntry(Object source, EntryWrittenEventArgs e) { EventLogEntry myEventLogEntry=e.Entry; if(myEventLogEntry!=null) { Console.WriteLine("Current message entry is: '" + myEventLogEntry.Message+"'"); } else { Console.WriteLine("The current entry is null"); } } }
#using <System.dll> using namespace System; using namespace System::Diagnostics; void MyOnEntry( Object^ source, EntryWrittenEventArgs^ e ) { EventLogEntry^ myEventLogEntry = e->Entry; if ( myEventLogEntry ) { Console::WriteLine( "Current message entry is: '{0}'", myEventLogEntry->Message ); } else { Console::WriteLine( "The current entry is null" ); } } int main() { try { EventLog^ myNewLog = gcnew EventLog; myNewLog->Log = "MyNewLog"; myNewLog->Source = "MySource"; // Create the source if it does not exist already. if ( !EventLog::SourceExists( "MySource" ) ) { EventLog::CreateEventSource( "MySource", "MyNewLog" ); Console::WriteLine( "CreatingEventSource" ); } // Write an entry to the EventLog. myNewLog->WriteEntry( "The Latest entry in the Event Log" ); int myEntries = myNewLog->Entries->Count; EventLogEntry^ entry = myNewLog->Entries[ myEntries - 1 ]; EntryWrittenEventArgs^ myEntryEventArgs = gcnew EntryWrittenEventArgs( entry ); MyOnEntry( myNewLog, myEntryEventArgs ); } catch ( Exception^ e ) { Console::WriteLine( "Exception Raised {0}", e->Message ); } }
import System.*; import System.Diagnostics.*; class MySample { public static void main(String[] args) { try { EventLog myNewLog = new EventLog(); myNewLog.set_Log("MyNewLog"); myNewLog.set_Source("MySource"); // Create the source if it does not exist already. if (!(EventLog.SourceExists("MySource"))) { EventLog.CreateEventSource("MySource", "MyNewLog"); Console.WriteLine("CreatingEventSource"); } // Write an entry to the EventLog. myNewLog.WriteEntry("The Latest entry in the Event Log"); int myEntries = myNewLog.get_Entries().get_Count(); EventLogEntry entry = myNewLog.get_Entries().get_Item((myEntries - 1)); EntryWrittenEventArgs myEntryEventArgs = new EntryWrittenEventArgs(entry); MyOnEntry(myNewLog, myEntryEventArgs); } catch (System.Exception e) { Console.WriteLine("Exception Raised" + e.get_Message()); } } //main protected static void MyOnEntry(Object source, EntryWrittenEventArgs e) { EventLogEntry myEventLogEntry = e.get_Entry(); if (myEventLogEntry != null) { Console.WriteLine("Current message entry is: '" + myEventLogEntry.get_Message() + "'"); } else { Console.WriteLine("The current entry is null"); } } //MyOnEntry } //MySample
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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
EntryWrittenEventArgs コンストラクタ
オーバーロードの一覧
名前 | 説明 |
---|---|
EntryWrittenEventArgs () | EntryWrittenEventArgs クラスの新しいインスタンスを初期化します。 |
EntryWrittenEventArgs (EventLogEntry) | 指定したイベント ログ エントリを使用して、EntryWrittenEventArgs クラスの新しいインスタンスを初期化します。 |
EntryWrittenEventArgs コンストラクタ ()
アセンブリ: System (system.dll 内)
構文
使用例
EntryWrittenEventArgs コンストラクタの例を次に示します。これは、カスタム EventLog オブジェクトを作成して、エントリを書き込みます。次に、カスタム EventLog 内の最初のエントリを使用して EntryWrittenEventArgs オブジェクトを作成します。このオブジェクトは、メッセージを通知するときに使用します。
Imports System Imports System.Diagnostics Class MySample Public Shared Sub Main() Try Dim myNewLog As New EventLog() myNewLog.Log = "MyNewLog" myNewLog.Source = "MySource" ' Create the source if it does not exist already. If Not EventLog.SourceExists("MySource") Then EventLog.CreateEventSource("MySource", "MyNewLog") Console.WriteLine("CreatingEventSource") End If ' Write an entry to the EventLog. myNewLog.WriteEntry("The Latest entry in the Event Log") Dim myEntryEventArgs As EntryWrittenEventArgs = _ New EntryWrittenEventArgs() MyOnEntry(myNewLog, myEntryEventArgs) Catch e As Exception Console.WriteLine("Exception Raised" + e.Message) End Try End Sub 'Main Protected Shared Sub MyOnEntry(ByVal source As Object, _ ByVal e As EntryWrittenEventArgs) If e.Entry Is Nothing Then Console.WriteLine("A new entry is written in MyNewLog.") End If End Sub 'MyOnEntry End Class 'MySample
using System; using System.Diagnostics; class MySample { public static void Main() { try { EventLog myNewLog = new EventLog(); myNewLog.Log = "MyNewLog"; myNewLog.Source="MySource"; // Create the source if it does not exist already. if(!EventLog.SourceExists("MySource")) { EventLog.CreateEventSource("MySource", "MyNewLog"); Console.WriteLine("CreatingEventSource"); } // Write an entry to the EventLog. myNewLog.WriteEntry("The Latest entry in the Event Log"); int myEntries = myNewLog.Entries.Count; EventLogEntry entry =myNewLog.Entries[myEntries-1]; EntryWrittenEventArgs myEntryEventArgs= new EntryWrittenEventArgs(); MyOnEntry(myNewLog,myEntryEventArgs); } catch(Exception e) { Console.WriteLine("Exception Raised" +e.Message); } } protected static void MyOnEntry(Object source, EntryWrittenEventArgs e) { if(e.Entry == null) Console.WriteLine("A new entry is written in MyNewLog."); } }
#using <System.dll> using namespace System; using namespace System::Diagnostics; void MyOnEntry( Object^ source, EntryWrittenEventArgs^ e ) { if ( !e->Entry ) Console::WriteLine( "A new entry is written in MyNewLog." ); } int main() { try { EventLog^ myNewLog = gcnew EventLog; myNewLog->Log = "MyNewLog"; myNewLog->Source = "MySource"; // Create the source if it does not exist already. if ( !EventLog::SourceExists( "MySource" ) ) { EventLog::CreateEventSource( "MySource", "MyNewLog" ); Console::WriteLine( "CreatingEventSource" ); } // Write an entry to the EventLog. myNewLog->WriteEntry( "The Latest entry in the Event Log" ); int myEntries = myNewLog->Entries->Count; EventLogEntry^ entry = myNewLog->Entries[ myEntries - 1 ]; EntryWrittenEventArgs^ myEntryEventArgs = gcnew EntryWrittenEventArgs; MyOnEntry( myNewLog, myEntryEventArgs ); } catch ( Exception^ e ) { Console::WriteLine( "Exception Raised{0}", e->Message ); } }
import System.*; import System.Diagnostics.*; class MySample { public static void main(String[] args) { try { EventLog myNewLog = new EventLog(); myNewLog.set_Log("MyNewLog"); myNewLog.set_Source("MySource"); // Create the source if it does not exist already. if (!(EventLog.SourceExists("MySource"))) { EventLog.CreateEventSource("MySource", "MyNewLog"); Console.WriteLine("CreatingEventSource"); } // Write an entry to the EventLog. myNewLog.WriteEntry("The Latest entry in the Event Log"); int myEntries = myNewLog.get_Entries().get_Count(); EventLogEntry entry = myNewLog.get_Entries(). get_Item((myEntries - 1)); EntryWrittenEventArgs myEntryEventArgs = new EntryWrittenEventArgs(); MyOnEntry(myNewLog, myEntryEventArgs); } catch (System.Exception e) { Console.WriteLine("Exception Raised" + e.get_Message()); } } //main private static void MyOnEntry(Object source, EntryWrittenEventArgs e) { if (e.get_Entry() == null) { Console.WriteLine("A new entry is written in MyNewLog."); } } //MyOnEntry } //MySample
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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- EntryWrittenEventArgs コンストラクタのページへのリンク