Professional Documents
Culture Documents
Mam Shazia
Maham Butt
Name Maham Salar Butt
Roll# 151-97
Semester 6th
Section BSCS-B
VISUAL PROGRAMMING
EVENTLOG
VISUAL PROGRAMMING
Event Logging
Information is the cornerstone of our economy.
Information is also key to software development. It
is helpful to know what your application is doing as
you are assembling core components, during
testing, and after the application is shipped.This
information can be available to you at a modest
cost without implementing new tools. VB.NET
defines the EventLog class in the
System.Diagnostics namespace. Using the
EventLog class you can gather significant application information about your deployed
application, and you can create a new log, logging anything and everything you need while
you are building and testing.
A user may not be able to readily reproduce or describe what went wrong while using your
application, but if you have logged critical information in your deployed application, the user
can export and mail you a copy of the event log. If the testers where you work are performing
whitebox testing then they can mail you a copy of the custom log, enabling you to scrutinize
the behavior of your code in a testing environment.
Many applications record errors and events in proprietary error logs, each with their own
format and user interface. Data from different applications can't easily be merged into one
complete report, requiring system administrators or support representatives to check a
variety of sources to diagnose problems.
Event logging provides a standard, centralized way for applications (and the operating system)
to record important software and hardware events. The event logging service records events
from various sources and stores them in a single collection called an event log. The Event
Viewer enables you to view logs; the programming interface also enables you to examine logs.
1
VISUAL PROGRAMMING
administrator may be able to identify problems (such as a failing hard disk) before they cause
damage.
ImportsSystem
Imports System.Diagnostics
5. To write to an event log, you need several pieces of information: Your message, the
name of the log you wish to write to (which will be created if it does not already exist),
and a string representing the source of the event. A particular source can be registered
with only a single event log, so if you wish to write messages to more than one log you
will need to define multiple sources.
2
VISUAL PROGRAMMING
6. Given all of this information, the first step is to use two static methods of the EventLog
class to first check whether your source exists, and if not, to create this source
associated with a particular event log. If the log name that you specify does not exist,
it will be created automatically when you write your first entry to it. If you do not
supply a log name to the CreateEventSource procedure, it will default to the
Application log.
7. To write a message into an event log, you can create a new EventLog object and use
the WriteEntry method which has several different overloaded versions. The simplest
method, which takes your message, and one of the more complex ones that supports
specifying the event ID and event type, are shown in the code below.
8. Save and run your code, and then check the Application log in the Event Viewer to see
your new events.
9. To write to an event log on a remote machine, simply change the the sMachine
variable to a machine name that you have privileges to write to the event log on.
Module Module1
Sub Main()
Dim sSource As String
Dim sLog As String
Dim sEvent As String
Dim sMachine as String
page.
3
VISUAL PROGRAMMING
sLog = "Application"
sEvent = "Sample Event"
sMachine = "."
End Sub
End Module
Sample code
4
VISUAL PROGRAMMING
Refrences
https://msdn.microsoft.com/en-us/library/windows/desktop/aa363652(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/windows/desktop/aa363632(v=vs.85).aspx
https://support.microsoft.com/en-us/help/301279/how-to-write-to-an-event-log-by-using-
visual-basic-net-or-visual-basic
http://www.visual-basic-tutorials.com/Tutorials/Controls/EventLog.html
https://www.codeguru.com/columns/vb/article.php/c6561/Using-the-EventLog-Class-in-
VBNET.htm
page.