Application.Error event

  • Thread starter Thread starter Sal Young
  • Start date Start date
S

Sal Young

I need help figuring out why the Application_Error event on my global.asax
is not working. When I run my web application, I do get an error on the
screen but no log file/record is created. Here is the code I have for the
Application_Error in my global.asax:

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim unhandledException As Exception =
Server.GetLastError().InnerException

If Not EventLog.SourceExists("Mileage Efficiency Calculator") Then
EventLog.CreateEventSource("Mileage Efficiency Calculator",
"Mileage Efficiency Calculator Log")
End If

Dim el As EventLog = New EventLog
el.Source = "Mileage Efficiency Calculator"
el.WriteEntry(unhandledException.Message)
Response.Write("An exceptin occurred: Created an entry in the event
log ")
Server.ClearError()
End Sub

Is this a permission issue? Is there something I need to set up so my
application has the rights to create the new log file?

Thanks for your help.
 
Hi Sal,

Yeah I think so. To check add your ASPNET/NETWORK SERVICE account
temporarily as an ADMIN user and see if it starts working. I wouldn't be
surprised if you don't need extended rights to create a new Eventlog source.

FWIW, I don't think it's a good idea to log stuff like that into the
EventLog. I would opt for an application specific log into an XML file in
the application directory or into a Database table. I would reserve the
EventLog for errors of more severity. Just my 2 cents <g>...


+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
 
Rick,

Thank you for your prompt reply. I did try what you suggested and added the
ASPNET account as a Administrator and that didn't solved the problem.

I'm really opposed to logging errors in a database because sometimes we get
database timeout errors; therefore, we can't access the database to log the
error.
 
Is there some sort of error that occurs with the logging? If the log is not
being written to you should be able to trap the error that is occuring in a
Try/Catch blcok.

As to logging to file - I understand that issue, hence the other suggestion
to log to an XML or text file. Whatever works.

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
 
Back
Top