473,395 Members | 1,629 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,395 software developers and data experts.

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.EventArgs) Handles MyBase.Load

Dim MissingPageErrorMsg As String
MissingPageErrorMsg = "A user has attempted to visit a non-existent page:
" & Request.QueryString("aspxerrorpath")
WriteToEventLog("Application", MissingPageErrorMsg)

End Sub
Sub WriteToEventLog(ByVal LogName As String, ByVal Message As String)
'Create event log if it doesn't exist
If (Not EventLog.SourceExists("Application")) Then
EventLog.CreateEventSource("Application", "Application")
End If
' Write to application event log
Dim Log As New EventLog("Application")
Log.Source = LogName
Log.WriteEntry(Message, EventLogEntryType.Error)
End Sub

--
_____
DC G
Jul 21 '05 #1
1 3059
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_MACHINE\SYSTEM\CurrentControlSet\Servic es\Eventlog\Application\{your
application name}

In your application you call the following

If (Not EventLog.SourceExists("Application")) Then
EventLog.CreateEventSource("Application", "Application")
End If

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

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Servic es\Eventlog\Application\Application

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. EventMessageFile - 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. CategoryMessageFile - optional REG_EXPAND_SZ string value
specifying the path to a category resource dll. This could be the same
file as the EventMessageFile 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:

--------------------
MessageIdTypedef=DWORD

SeverityNames=(Success=0x0:STATUS_SEVERITY_SUCCESS
Information=0x1:STATUS_SEVERITY_INFORMATION
Warning=0x2:STATUS_SEVERITY_WARNING
Error=0x3:STATUS_SEVERITY_ERROR
)

MessageId=0x03EF
Severity=Error
SymbolicName=MSG_ERROR
Language=English
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=0x03EF
Severity=Information
SymbolicName=ERR_MSG_MISSING_PAGE
Language=English
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.EventArgs) _
Handles MyBase.Load

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

If {...some test that load failed...} Then
WriteToEventLog("MyApplication", ERR_MSG_MISSING_PAGE, _
Request.QueryString("aspxerrorpath"))
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.SourceExists(SourceName)) Then
EventLog.CreateEventSource(SourceName, "Application")
End If

'Write to application event log
Dim Log As New EventLog("Application")
Log.Source = SourceName
Log.WriteEntry(Message, EventLogEntryType.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
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
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...
1
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...
0
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...
3
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...
0
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...
3
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...
1
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...
10
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.