This documentation is archived and is not being maintained.

EntryWrittenEventArgs Constructor

.NET Framework 1.1

Initializes a new instance of the EntryWrittenEventArgs class.

Overload List

Initializes a new instance of the EntryWrittenEventArgs class.

[Visual Basic] Public Sub New()
[C#] public EntryWrittenEventArgs();
[C++] public: EntryWrittenEventArgs();
[JScript] public function EntryWrittenEventArgs();

Initializes a new instance of the EntryWrittenEventArgs class with the specified event log entry.

[Visual Basic] Public Sub New(EventLogEntry)
[C#] public EntryWrittenEventArgs(EventLogEntry);
[C++] public: EntryWrittenEventArgs(EventLogEntry*);
[JScript] public function EntryWrittenEventArgs(EventLogEntry);


[Visual Basic, C#, C++] The following example demonstrates the ctor 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, C#, C++] Note   This example shows how to use one of the overloaded versions of the EntryWrittenEventArgs constructor. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Imports System
Imports System.Diagnostics

Class MySample
   Public Shared Sub Main()
         Dim myNewLog As New EventLog()
         ' Create the source if it does not exist already.
         If Not EventLog.SourceExists("MySource") Then
            EventLog.CreateEventSource("MySource", "MyNewLog")
         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 + "'")
         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()
            EventLog myNewLog = new EventLog();
            myNewLog.Log = "MyNewLog";
            // Create the source if it does not exist already.
               EventLog.CreateEventSource("MySource", "MyNewLog");
            // 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);
         catch(Exception e)
            Console.WriteLine("Exception Raised" +e.Message);
      protected static void MyOnEntry(Object source, EntryWrittenEventArgs e)
         EventLogEntry myEventLogEntry=e.Entry;
            Console.WriteLine("Current message entry is: '" 
                              + myEventLogEntry.Message+"'");
            Console.WriteLine("The current entry is null");

#using <mscorlib.dll>
#using <System.dll>

using namespace System;
using namespace System::Diagnostics;

    void MyOnEntry(Object* source, EntryWrittenEventArgs* e) {
        EventLogEntry* myEventLogEntry=e->Entry;
        if (myEventLogEntry) {
            Console::WriteLine(S"Current message entry is: '{0}'", myEventLogEntry->Message);
        } else {
            Console::WriteLine(S"The current entry is null");

    int main() {
        try {
            EventLog* myNewLog = new EventLog();
            myNewLog->Log = S"MyNewLog";
            // Create the source if it does not exist already.
            if (!EventLog::SourceExists(S"MySource")) {
                EventLog::CreateEventSource(S"MySource", S"MyNewLog");
            // 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(entry);
            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.

See Also

EntryWrittenEventArgs Class | EntryWrittenEventArgs Members | System.Diagnostics Namespace