Export (0) Print
Expand All

EntryWrittenEventArgs Class

Provides data for the EntryWritten event.

For a list of all members of this type, see EntryWrittenEventArgs Members.

System.Object
   System.EventArgs
      System.Diagnostics.EntryWrittenEventArgs

[Visual Basic]
Public Class EntryWrittenEventArgs
   Inherits EventArgs
[C#]
public class EntryWrittenEventArgs : EventArgs
[C++]
public __gc class EntryWrittenEventArgs : public EventArgs
[JScript]
public class EntryWrittenEventArgs extends EventArgs

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Example

[Visual Basic, C#, C++] The following example demonstrates the EntryWrittenEventArgs constructor. It creates a custom EventLog object and writes an entry into it. Then it creates an EntryWrittenEventArgs object using the first entry in the custom EventLog. This object is used to notify a message.

[Visual Basic] 
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

[C#] 
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.");
      }
   }

[C++] 
#using <mscorlib.dll>
#using <System.dll>

using namespace System;
using namespace System::Diagnostics;

void MyOnEntry(Object* source, EntryWrittenEventArgs* e) {
    if(!e->Entry)
        Console::WriteLine(S"A new entry is written in MyNewLog.");
}

int main() {
    try {
        EventLog* myNewLog = new EventLog();
        myNewLog->Log = S"MyNewLog";
        myNewLog->Source = S"MySource";
        // Create the source if it does not exist already.
        if (!EventLog::SourceExists(S"MySource")) {
            EventLog::CreateEventSource(S"MySource", S"MyNewLog");
            Console::WriteLine(S"CreatingEventSource");
        }
        // Write an entry to the EventLog.
        myNewLog->WriteEntry(S"The Latest entry in the Event Log");
        int myEntries = myNewLog->Entries->Count;
        EventLogEntry* entry = myNewLog->Entries->Item[myEntries-1];
        EntryWrittenEventArgs* myEntryEventArgs = new EntryWrittenEventArgs();
        MyOnEntry(myNewLog, myEntryEventArgs);
    } catch (Exception* e) {
        Console::WriteLine(S"Exception Raised{0}", e->Message);
    }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Diagnostics

Platforms: Windows NT Server 4.0, Windows NT Workstation 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System (in System.dll)

See Also

EntryWrittenEventArgs Members | System.Diagnostics Namespace | EntryWritten | EntryWrittenEventHandler | EventLog

Show:
© 2014 Microsoft