473,804 Members | 4,223 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Write log description

I have some code that writes log entries upon errors in an VB.NET web app.

I can write the Message but in the log, preceding my message is the
following:

Description:
The description for Event ID ( 0 ) in Source ( Application ) cannot be
found. The local computer may not have the necessary registry information or
message DLL files to display messages from a remote computer. You may be
able to use the /AUXSOURCE= flag to retrieve this description; see Help and
Support for details. The following information is part of the event: <MY
MESSAGE SHOWS UP HERE>
How can I get rid of this and/or add the Event ID as suggested? Here's my
code

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

Dim MissingPageErro rMsg As String
MissingPageErro rMsg = "A user has attempted to visit a non-existent page:
" & Request.QuerySt ring("aspxerror path")
WriteToEventLog ("Applicatio n", MissingPageErro rMsg)

End Sub
Sub WriteToEventLog (ByVal LogName As String, ByVal Message As String)
'Create event log if it doesn't exist
If (Not EventLog.Source Exists("Applica tion")) Then
EventLog.Create EventSource("Ap plication", "Applicatio n")
End If
' Write to application event log
Dim Log As New EventLog("Appli cation")
Log.Source = LogName
Log.WriteEntry( Message, EventLogEntryTy pe.Error)
End Sub

--
_____
DC G
Jul 21 '05 #1
1 3086
The whole mechanism of writing events to the log is rather involved
and can be complex depending on how detailed you want to get with your
messaging. I will give a brief overview of what I recently learned
and implemented but a good explanation of all the details can be found
here:

http://msdn.microsoft.com/library/de...nt_logging.asp

When you write a message to the Windows EventLog, the system looks in
the registry to see if a message resource file has been associated
with the Application Name you specify.

HKEY_LOCAL_MACH INE\SYSTEM\Curr entControlSet\S ervices\Eventlo g\Application\{ your
application name}

In your application you call the following

If (Not EventLog.Source Exists("Applica tion")) Then
EventLog.Create EventSource("Ap plication", "Applicatio n")
End If

which checks to see if the following registry key exists and creates
it if not:

HKEY_LOCAL_MACH INE\SYSTEM\Curr entControlSet\S ervices\Eventlo g\Application\A pplication

The documentation I've read says that you don't really need to create
the EventSource because a call to WriteEvent will create the source if
it doesn't already exist. However, to use predefined messages you
definitely need to create the event source in the registry manually
first.

Under this registry key there needs to be several values:

1. EventMessageFil e - REG_EXPAND_SZ string value specifying the path
to a message resource dll (I'll discuss that file in a moment)

2. TypesSupported - REG_DWORD value using bit masks to indicate
whether your message file handles Information, Warning, Error,
AuditSuccess, and/or AuditFailure messages.

3. CategoryMessage File - optional REG_EXPAND_SZ string value
specifying the path to a category resource dll. This could be the same
file as the EventMessageFil e or a separate file.

4. CategoryCount - optional REG_DWORD value specifying how many
Category types have been specified in the Category resource dll.
The message resource dll is created by compiling a text file through
the mc command line executable. This generates a resource file with an
rc extension. This file then needs to be resource compiled with the rc
command line executable resulting in a resource dll that you can use
for the registry entry above.

The text file specifies the message text associated with each Event ID
(or error code). A message file declaration looks something like
this:

--------------------
MessageIdTypede f=DWORD

SeverityNames=( Success=0x0:STA TUS_SEVERITY_SU CCESS
Information=0x1 :STATUS_SEVERIT Y_INFORMATION
Warning=0x2:STA TUS_SEVERITY_WA RNING
Error=0x3:STATU S_SEVERITY_ERRO R
)

MessageId=0x03E F
Severity=Error
SymbolicName=MS G_ERROR
Language=Englis h
A user has attempted to visit a non-existent page
..
--------------------

Note that the Severity value specified for a MessageID sets the high
order bits of the resulting Event ID. In other words, the message
declared above results in an Event ID of 0xC00003EF. You must pass in
this error code to get a match.

The message text you declare in the text file can have insert values
as well, specified by %n where n is 1 through 99. The message string
you pass into the call to write to the event log is used as the insert
value. If you pass in a string with embedded chr$(0), each substring
is used as a separate insert value.

--------------------
MessageId=0x03E F
Severity=Inform ation
SymbolicName=ER R_MSG_MISSING_P AGE
Language=Englis h
A user has attempted to visit a non-existent page: %1
..
--------------------

You would then change your code to something like this

Public Const ERR_MSG_MISSING _PAGE = &HC00003EF

Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArg s) _
Handles MyBase.Load

{...some code that loads the page...}

If {...some test that load failed...} Then
WriteToEventLog ("MyApplication ", ERR_MSG_MISSING _PAGE, _
Request.QuerySt ring("aspxerror path"))
End If

End Sub

Sub WriteToEventLog (ByVal SourceName As String, _
ByVal EventID as Integer, _
ByVal Message As String)
'Create event log if it doesn't exist
If (Not EventLog.Source Exists(SourceNa me)) Then
EventLog.Create EventSource(Sou rceName, "Applicatio n")
End If

'Write to application event log
Dim Log As New EventLog("Appli cation")
Log.Source = SourceName
Log.WriteEntry( Message, EventLogEntryTy pe.Error, EventID)
End Sub

HTH,
Michael Levy
Jul 21 '05 #2

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

Similar topics

2
5416
by: Chua Wen Ching | last post by:
Hi there, I have 2 questions to ask. 1) I have this code... XmlDocument doc = new XmlDocument(); doc.Load(myXmlPath); int maxValue = 0;
2
1180
by: Maileen | last post by:
Hi, I have an existing XML file that i would like to update. I know how to read it and how to write in XML file, but i have a problem to update a value inside it. for example the following XML file : <?xml version="1.0"?> <SLAReport>
1
428
by: DC Gringo | last post by:
I have some code that writes log entries upon errors in an VB.NET web app. I can write the Message but in the log, preceding my message is the following: Description: The description for Event ID ( 0 ) in Source ( Application ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this...
0
1510
by: sk.rasheedfarhan | last post by:
Hi all, According to my project requirement I have to write the NT Event information of SQL Server into EventLog viewer. For more clear I want to write the following information into Application log file: ------------------------------------------------------------------------------------------------------ Event ID :17055
3
18506
by: sk.rasheedfarhan | last post by:
Hi all, According to my project requirement I have to write the NT Event information of SQL Server into EventLog viewer. For more clear I want to write the following information into Application log file: ---------------------------------------------------------------------------­---------------------------
0
3588
by: DC | last post by:
The problem I'm using the .NET GridView and FormView objects for the first time and im getting the error "An OleDbParameter with ParameterName '@ID' is not contained by this OleDbParameterCollection" whenI try to write a new record. Delete and Modify work fine its just the add record function causes the error.
3
3897
by: Brett_A | last post by:
I'm trying to write data from a form using a text box (textarea) that has a return after each item. For example: email1@domain.com email2@domain.com email3@domain.com email4@domain.com I'm getting the data written to the SQL server table fine, but every item after the first is getting written with a special character
1
1497
by: kelvin273 | last post by:
hello, i've an xml file and i want to transform it to another one with only certain attribute in certain nodes (!) for example, all the node have id, title and description are attributes. but i want the first node display only title, the second id and title, the third only description, etc. the xml is: <guide id="" title="" description=""> <version id="" title="" description=""> <module id="" title="" description=""> <unit...
10
2158
by: cjard | last post by:
I have a client and server that enjoy the following simple dialogue: Client connects Client sends request Server sends response Client disconnects This is the way it must be. The response must be wrapped in a start and end byte 0x02 and 0x03 resepctively.
0
9579
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10577
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10332
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10320
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9150
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5521
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4299
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.