My last experience with VB was VB3. I am using Visual Studio 2005 now and
things are very different.
I have taken the code you provided and put it in the program and now it runs
but does not report anything. Is this what you meant with your suggestion?
Thanks,
Imports System
Imports System.Environment
Imports System.Diagnostics
Imports System.Threading
Namespace Microsoft.Samples
Module LogMonitor
Public Event EntryWritten As EntryWrittenEventHandler
Dim WithEvents evtApp As New EventLog("Application")
Dim WithEvents evtSys As New EventLog("System")
Dim WithEvents evtSec As New EventLog("Security")
Private signal As AutoResetEvent
Public Sub Main()
Dim log As String
Dim aLog As EventLog
Dim machine As String = "."
log = "system"
If (Not EventLog.Exists(log, machine)) Then
MsgBox("The sytem log does not exist!", , "Error")
Exit Sub
End If
log = "application"
If (Not EventLog.Exists(log, machine)) Then
MsgBox("The application log does not exist!", , "Error")
Exit Sub
End If
log = "security"
If (Not EventLog.Exists(log, machine)) Then
MsgBox("The security log does not exist!", , "Error")
Exit Sub
End If
aLog = New EventLog
aLog.MachineName = machine
AddHandler aLog.EntryWritten, AddressOf OnEntryWritten
' aLog.EnableRaisingEvents = True This causes the
program to crash on my PC
signal = New AutoResetEvent(False)
signal.WaitOne()
End Sub
Sub OnEntryWritten(ByVal source As Object, ByVal e As
System.Diagnostics.EntryWrittenEventArgs) Handles evtApp.EntryWritten,
evtSec.EntryWritten, evtSys.EntryWritten
MsgBox(e.Entry.Message, , "Eventlog Monitor")
End Sub
Private Sub evtApp_EntryWritten(ByVal sender As Object, ByVal e As
System.Diagnostics.EntryWrittenEventArgs) Handles evtApp.EntryWritten,
evtSec.EntryWritten, evtSys.EntryWritten
End Sub
End Module
End Namespace