473,698 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_Err or(ByVal sender As Object, ByVal e As EventArgs)
' Fires when an error occurs
Dim ErrorDescriptio n As String = Server.GetLastE rror.ToString

'Creation of event log if it does not exist
Dim EventLogName As String = "Test"
If (Not EventLog.Source Exists(EventLog Name)) Then ' <--
stepping through code seems to end here
EventLog.Create EventSource(Eve ntLogName, EventLogName)
End If

' Inserting into event log
Dim Log As New EventLog
Log.Source = EventLogName
Log.WriteEntry( ErrorDescriptio n, EventLogEntryTy pe.Error)

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

Thanks!

Matt
Nov 19 '05 #1
2 3211
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********@yah oo.com> wrote in message
news:38******** *****@individua l.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_Err or(ByVal sender As Object, ByVal e As EventArgs)
' Fires when an error occurs
Dim ErrorDescriptio n As String = Server.GetLastE rror.ToString

'Creation of event log if it does not exist
Dim EventLogName As String = "Test"
If (Not EventLog.Source Exists(EventLog Name)) Then ' <--
stepping through code seems to end here
EventLog.Create EventSource(Eve ntLogName, EventLogName)
End If

' Inserting into event log
Dim Log As New EventLog
Log.Source = EventLogName
Log.WriteEntry( ErrorDescriptio n, EventLogEntryTy pe.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_mach ine\system\curr entcontrolset\s ervices\eventlo g\application

-- bruce (sqlwork.com)
"MattB" <so********@yah oo.com> wrote in message
news:38******** *****@individua l.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_Err or(ByVal sender As Object, ByVal e As EventArgs)
| ' Fires when an error occurs
| Dim ErrorDescriptio n As String = Server.GetLastE rror.ToString
|
| 'Creation of event log if it does not exist
| Dim EventLogName As String = "Test"
| If (Not EventLog.Source Exists(EventLog Name)) Then ' <--
| stepping through code seems to end here
| EventLog.Create EventSource(Eve ntLogName, EventLogName)
| End If
|
| ' Inserting into event log
| Dim Log As New EventLog
| Log.Source = EventLogName
| Log.WriteEntry( ErrorDescriptio n, EventLogEntryTy pe.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
1170
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 permissions as i read in some article but this didn't help to so i disable the JIT from the IDE properties and then i got those errors . please advice.
1
1148
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 user name to be displayed in the field USER in the evcent log. We can't find out how this value would be written to this field in the log entry. We have no trouble getting the user name, just writing it to the log. Can anyone tell us how this should...
3
1063
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 acces is not allowed. I know, that it is running in context of ASP.NET (or Network Service), but how can i do this, that will run as "someuser", that will be a domain user? Maybe there is other method for it? Leszek
6
3404
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. This application has to write to the application event log. After deployment of the application I have verified that my source “MySource” exists in the Application event log. I then wrote some text to the event source in a forms app and...
0
3233
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 appear on our domain controllers (Security event log): Event Type: Failure Audit Event Source: Security
19
2203
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 by using ajax. If not present is gracefully stay silent. The problem is now that when the JS is not present (and it can be) MSIE gives a lot of errors and one has to kill it.
7
5131
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 it's the 64-bit version of Exchange 2007 installed on Windows Server 2003 Enterprise x64, while the Exchange 2007 SDK samples seem mostly geared toward 32-bit. Even at that, I was able to build the TLB and install it into COM+ Component Services,...
59
3456
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
1285
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. The users run the application on terminal servers. What is the best practice? How do I get round this?
0
8675
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9160
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
9029
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...
0
8862
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
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
3050
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
2331
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2002
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.