Error messages

G

Gary

I am trying to write to a event log using the EventLog Class in a ASP.net
application.
The following code was added to 'Aplication_Error' subroutine in the
'Global.asax' file
Public Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)

Dim ErrorDescription As String = Server.GetLastError.ToString()

'Creation of event log if it does not exist

Dim EventLogName As String = "ErrorSample"

If Not EventLog.sourceExists(EventLogName) Then
' Problem1 Error Message = SourceExists is not a member of
EventLog

EventLog.CreateEventSource(EventLogName, EventLogName)
' Problem2 Error Message = CreateEventSource is not a member of
EventLog

End If

'Inserting into eventlog

Dim Log As New eventlog()

Log.Source = EventLogName

Log.WriteEntry(ErrorDescription, EventLogEntryType.Error)

End Sub

I am using Microsoft Development Environment 2002 version 7.0.9466 &
Microsoft.NET framework 1.0 version 1.0.3705

Please suggest some solution to the above problem.

TIA,

Gary
 
G

Gary

Kevin,

There are two problems
1. Error Message = SourceExists is not a member of EventLog at line:
If Not EventLog.sourceExists(EventLogName) Then

2. Error Message = CreateEventSource is not a member of EventLog at line:
EventLog.CreateEventSource(EventLogName, EventLogName)

The problems were written inline the message :)

Please help me.
Gary
 
K

Kevin Spencer

Sorry Gary. I missed the inline remarks!

Very strange. The first thing I notice is that you didn't include any code
that, for example, imports System.Diagnostics. Is it there? Another
possibility is that you created an instance of The
System.Diagnostics.EventLog class and named it "EventLog." Did you? The 2
methods you are having problems with are Shared methods, which means that
they can be invoked without an instance of the class. You might try revising
each of them something like the following:

If Not System.Diagnostics.EventLog.SourceExists(EventLogName) Then

This would certainly clear up any possible ambiguity that exists.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Neither a follower nor a lender be.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top