Home All Groups Group Topic Archive Search About
Author
16 May 2006 1:38 AM
Ben
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,

Author
16 May 2006 3:31 AM
Ken Tucker [MVP]
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/library/system.diagnostics.eventlog.entrywritten.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
----------------
Show quoteHide quote
"Ben" <ben553***@yahoo.com> wrote in message
news:uhPy4lIeGHA.2416@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,
>
Author
16 May 2006 3:49 PM
Ben
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



Show quoteHide quote
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:efDqNlJeGHA.764@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/library/system.diagnostics.eventlog.entrywritten.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" <ben553***@yahoo.com> wrote in message
> news:uhPy4lIeGHA.2416@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,
>>
>
>
Author
21 May 2006 8:22 PM
Ben
Is this what you meant?

Thanks,
Ben

'-----------------------------------------------------------------------
' This file is part of the Microsoft .NET Framework SDK Code Samples.
'
' Copyright (C) Microsoft Corporation. All rights reserved.
'
'This source code is intended only as a supplement to Microsoft
'Development Tools and/or on-line documentation. See these other
'materials for detailed information regarding Microsoft code samples.
'
'THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
'KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
'IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'PARTICULAR PURPOSE.
'-----------------------------------------------------------------------
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")

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
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

End Module

End Namespace