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
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:ef*************@TK2MSFTNGP05.phx.gbl...
Ben,
Create an eventlog class for each of the logs. Handle the
entrywritten event for each of the variables.
http://msdn2.microsoft.com/en-us/lib...rywritten.aspx
Dim WithEvents evtApp As New EventLog("Applcation")
Dim WithEvents evtSys As New EventLog("System")
Dim WithEvents evtSec As New EventLog("Security")
Private Sub evtApp_EntryWritten(ByVal sender As Object, ByVal e As
System.Diagnostics.EntryWrittenEventArgs) Handles evtApp.EntryWritten,
evtSec.EntryWritten, evtSys.EntryWritten
End Sub
Ken
----------------
"Ben" <be*******@yahoo.com> wrote in message
news:uh**************@TK2MSFTNGP03.phx.gbl...I am trying to write an eventlog monitor. I am using the sample code
provided by VB2005 SDK as the bases for my application. I need to monitor
all three logs (application, system, and security). How can I monitor all
three logs at once?
Thanks,