Occurs when an entry is written to an event log on the local computer.
Namespace:
System.Diagnostics
Assembly:
System (in System.dll)
Visual Basic (Declaration)
Public Event EntryWritten As EntryWrittenEventHandler
Dim instance As EventLog
Dim handler As EntryWrittenEventHandler
AddHandler instance.EntryWritten, handler
public event EntryWrittenEventHandler EntryWritten
public:
event EntryWrittenEventHandler^ EntryWritten {
void add (EntryWrittenEventHandler^ value);
void remove (EntryWrittenEventHandler^ value);
}
JScript does not support events.
To get event notifications, you must set EnableRaisingEvents to true. You can only receive event notifications when entries are written on the local computer. You cannot receive notifications for entries written on remote computers.
When you create an EntryWritten delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, until you remove the delegate. For more information about handling events with delegates, see Consuming Events.
The system responds to WriteEntry only if the last write event occurred at least six seconds previously. This implies you will only receive one EntryWritten event notification within a six-second interval, even if more than one event log change occurs. If you insert a sufficiently long sleep interval (around 10 seconds) between calls to WriteEntry, you are less likely to miss an event. However, if write events occur more frequently, you might not recieve the event notification until the next interval. Typically, missed event notifications are not lost, but delayed.
The following example handles an entry written event.
Option Explicit On
Option Strict On
Imports System
Imports System.Diagnostics
Imports System.Threading
Class MySample
' This member is used to wait for events.
Private Shared signal As AutoResetEvent
Public Shared Sub Main()
signal = New AutoResetEvent(False)
Dim myNewLog As New EventLog("Application", ".", "testEventLogEvent")
AddHandler myNewLog.EntryWritten, AddressOf MyOnEntryWritten
myNewLog.EnableRaisingEvents = True
myNewLog.WriteEntry("Test message", EventLogEntryType.Information)
signal.WaitOne()
End Sub ' Main
Public Shared Sub MyOnEntryWritten(ByVal [source] As Object, ByVal e As EntryWrittenEventArgs)
Console.WriteLine("In event handler")
signal.Set()
End Sub ' MyOnEntryWritten
End Class ' MySample
using System;
using System.Diagnostics;
using System.Threading;
class MySample
{
// This member is used to wait for events.
static AutoResetEvent signal;
public static void Main()
{
signal = new AutoResetEvent(false);
EventLog myNewLog = new EventLog("Application", ".", "testEventLogEvent");
myNewLog.EntryWritten += new EntryWrittenEventHandler(MyOnEntryWritten);
myNewLog.EnableRaisingEvents = true;
myNewLog.WriteEntry("Test message", EventLogEntryType.Information);
signal.WaitOne();
}
public static void MyOnEntryWritten(object source, EntryWrittenEventArgs e)
{
Console.WriteLine("In event handler");
signal.Set();
}
}
#using <System.dll>
using namespace System;
using namespace System::Diagnostics;
using namespace System::Threading;
ref class MySample
{
private:
// This member is used to wait for events.
static AutoResetEvent^ signal;
public:
static void main()
{
signal = gcnew AutoResetEvent( false );
EventLog^ myNewLog = gcnew EventLog;
myNewLog->Source = "testEventLogEvent";
myNewLog->EntryWritten += gcnew EntryWrittenEventHandler( MyOnEntryWritten );
myNewLog->EnableRaisingEvents = true;
myNewLog->WriteEntry("Test message", EventLogEntryType::Information);
signal->WaitOne();
}
static void MyOnEntryWritten( Object^ /*source*/, EntryWrittenEventArgs^ /*e*/ )
{
Console::WriteLine("In event handler");
signal->Set();
}
};
int main()
{
MySample::main();
}
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Reference