Share via


EntryWrittenEventArgs コンストラクタ ()

EntryWrittenEventArgs クラスの新しいインスタンスを初期化します。

名前空間: System.Diagnostics
アセンブリ: System (system.dll 内)

構文

'宣言
Public Sub New
'使用
Dim instance As New EntryWrittenEventArgs
public EntryWrittenEventArgs ()
public:
EntryWrittenEventArgs ()
public EntryWrittenEventArgs ()
public function EntryWrittenEventArgs ()

使用例

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。

バージョン情報

.NET Framework

サポート対象 : 2.0、1.1、1.0

参照

関連項目

EntryWrittenEventArgs クラス
EntryWrittenEventArgs メンバ
System.Diagnostics 名前空間