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

Writing errors to the Event Log

I'm writing some code to log errors in a web app (vb/asp.net). I found a
straightforward-looking example here:
http://www.c-sharpcorner.com/Code/20...lingASPNEt.asp

But mine doesn't seem to be working.

If I step through the code I put in global.asax.vb it seems to get to
the line where it checks for the existence of the log and then returns
without writing anything to the event log. I don;t know why or how to
troubleshoot it. Any suggestions? Here's the code I'm using:

----------------
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Fires when an error occurs
Dim ErrorDescription As String = Server.GetLastError.ToString

'Creation of event log if it does not exist
Dim EventLogName As String = "Test"
If (Not EventLog.SourceExists(EventLogName)) Then ' <--
stepping through code seems to end here
EventLog.CreateEventSource(EventLogName, EventLogName)
End If

' Inserting into event log
Dim Log As New EventLog
Log.Source = EventLogName
Log.WriteEntry(ErrorDescription, EventLogEntryType.Error)

End Sub
----------------

Thanks!

Matt
Nov 19 '05 #1
2 3200
Is it throwing an exception?
Asp.net does not by default have rights to create new event logs. Try
playing around with security settings.

"MattB" <so********@yahoo.com> wrote in message
news:38*************@individual.net...
I'm writing some code to log errors in a web app (vb/asp.net). I found a
straightforward-looking example here:
http://www.c-sharpcorner.com/Code/20...lingASPNEt.asp

But mine doesn't seem to be working.

If I step through the code I put in global.asax.vb it seems to get to the
line where it checks for the existence of the log and then returns without
writing anything to the event log. I don;t know why or how to troubleshoot
it. Any suggestions? Here's the code I'm using:

----------------
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Fires when an error occurs
Dim ErrorDescription As String = Server.GetLastError.ToString

'Creation of event log if it does not exist
Dim EventLogName As String = "Test"
If (Not EventLog.SourceExists(EventLogName)) Then ' <--
stepping through code seems to end here
EventLog.CreateEventSource(EventLogName, EventLogName)
End If

' Inserting into event log
Dim Log As New EventLog
Log.Source = EventLogName
Log.WriteEntry(ErrorDescription, EventLogEntryType.Error)

End Sub
----------------

Thanks!

Matt

Nov 19 '05 #2
asp.net usually does not have permission to create the event source which is
actually a registry entry. create the source yourself, or give the asp.net
account write permission to the register using regedt32. the path is:

hkey_local_machine\system\currentcontrolset\servic es\eventlog\application

-- bruce (sqlwork.com)
"MattB" <so********@yahoo.com> wrote in message
news:38*************@individual.net...
| I'm writing some code to log errors in a web app (vb/asp.net). I found a
| straightforward-looking example here:
| http://www.c-sharpcorner.com/Code/20...lingASPNEt.asp
|
| But mine doesn't seem to be working.
|
| If I step through the code I put in global.asax.vb it seems to get to
| the line where it checks for the existence of the log and then returns
| without writing anything to the event log. I don;t know why or how to
| troubleshoot it. Any suggestions? Here's the code I'm using:
|
| ----------------
| Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
| ' Fires when an error occurs
| Dim ErrorDescription As String = Server.GetLastError.ToString
|
| 'Creation of event log if it does not exist
| Dim EventLogName As String = "Test"
| If (Not EventLog.SourceExists(EventLogName)) Then ' <--
| stepping through code seems to end here
| EventLog.CreateEventSource(EventLogName, EventLogName)
| End If
|
| ' Inserting into event log
| Dim Log As New EventLog
| Log.Source = EventLogName
| Log.WriteEntry(ErrorDescription, EventLogEntryType.Error)
|
| End Sub
| ----------------
|
| Thanks!
|
| Matt
Nov 19 '05 #3

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

Similar topics

0
by: Tiraman | last post by:
Hi , i m getting the following errors under the eventlog while i m trying to run some class that i wrote. at the first i got an error about the just-in-time : access denied and i added the...
1
by: Bob Dufour | last post by:
Using the .NET eventlog class to log application errors that are viewable in the Windows event viewer. We write to a custom log. WE can Write our error messages to it OK but we want the Current...
3
by: Leszek | last post by:
Hello! I'm creating application, that will get data from SQL and show it. The end of it is writing to log informations from which table it was readed. And there is a problem - Requested registry...
6
by: JeffDotNet | last post by:
Writing to a registered source in the Application event log I have an asp.net framework 2.0 app that I created on a winxp machine and now I am deploying it to IIS6 on a win server2003 machine. ...
0
by: robpimentel | last post by:
Hi, I've been using DB2 for about 1 week, so please bear with me. DB2 Connect Enterprise Edition v8.1 FixPack 5 Windows Server 2003 Standard Edition SP1 Here is an error that continues to...
19
by: pamelafluente | last post by:
Hi Guys, I am trying to include my little script in my html report. I have done an external JS file which contains it. If you remember, you have helped me to detect if the asp page was present...
7
by: Don | last post by:
Getting errors after following the MSDN article on using VB.NET (and VS2005) for "Implementing a Managed OnSave Event Sink" for Exchange Server 2007. Not sure, but part of the problem may be that...
59
by: riva | last post by:
I am developing a compression program. Is there any way to write a data to file in the form of bits, like write bit 0 then bit 1 and then bit 1 and so on ....
1
by: JTC^..^ | last post by:
I want my application to write errors to the windows event log. If a user run the application on the server for the first time and they get an error the application cannot write to the event log....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...

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.