473,396 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

eventlog monitoring

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,
May 16 '06 #1
3 4813
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,

May 16 '06 #2
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

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


May 16 '06 #3
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
May 21 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joe | last post by:
I am trying to read the EventLog of different servers on the network. If I run the script in a command line, it works well. But when I try to put the script into the Web server (IIS in Windows...
0
by: Jacob Colding | last post by:
Hello, I have created a a logging mechanism, that writes mesages to a custom event log. On each check it verifies whether the requested source is registered to the "IPS" log. If not, it changes...
2
by: rgilmore | last post by:
Our app uses the EventLog class to write errors to the event log. Sometimes the app runs unattended for days, and if errors are occurring, the event log can fill up, causing the app to have no way...
2
by: Next | last post by:
Hello all, I have a windows service that was suppose to write some events into its own EventLog. I created the EventLog using the component on VS 2003 toolbar Added an installer for it. Set...
1
by: MAL | last post by:
Hello, I am writing a service program that writes to a custom EventLog. I would like the two classes used in the service to write messages to the same log ideally using a different Source name...
1
by: martin | last post by:
Hi, I'm having some problems with the System.Diagnostics.EventLog class in .NET 2.0 I need to recreate an event message source inside a new log but the messages keeps ending up in the old...
4
by: bartlomiej.szafraniec | last post by:
Hello! How I can gain access to event log on remote machine? Computers are in the same network but they are not in domain, they are only in the same workgroup. I've tried MachineName property in...
0
by: rene | last post by:
I'm trying to use costome categories in my eventlog for a program I'm writing. But I have some problems with it, I cant get it to work. Checklist for how I did this. 1. Created a...
1
by: Jeff | last post by:
hi ..Net 2.0 I've created the code below and think I've executed it. After I thought I've executed it I checked in EventLog on the computer (win2k3) and no entry was added. This could mean 2...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.