Writing errors to the Event Log

Discussion in 'ASP .Net' started by MattB, Feb 28, 2005.

  1. MattB

    MattB Guest

    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/2002/May/CustomErrorHandlingASPNEt.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
    MattB, Feb 28, 2005
    #1
    1. Advertising

  2. MattB

    Marina Guest

    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" <> wrote in message
    news:...
    > 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/2002/May/CustomErrorHandlingASPNEt.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
    Marina, Feb 28, 2005
    #2
    1. Advertising

  3. MattB

    bruce barker Guest

    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\services\eventlog\application

    -- bruce (sqlwork.com)


    "MattB" <> wrote in message
    news:...
    | 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/2002/May/CustomErrorHandlingASPNEt.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
    bruce barker, Mar 1, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Henrik_the_boss
    Replies:
    0
    Views:
    2,647
    Henrik_the_boss
    Nov 5, 2003
  2. =?Utf-8?B?VG9tIFdpbmdlcnQ=?=

    My.Log.Writeexception not writing to Application Event Log.

    =?Utf-8?B?VG9tIFdpbmdlcnQ=?=, Jan 20, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    2,371
    =?Utf-8?B?VG9tIFdpbmdlcnQ=?=
    Jan 20, 2006
  3. Graham Harris

    Writing ASP.NET errors to the NT Applicaion Event Log

    Graham Harris, May 10, 2005, in forum: ASP .Net Security
    Replies:
    3
    Views:
    197
    Dominick Baier [DevelopMentor]
    May 14, 2005
  4. Tom Wingert
    Replies:
    0
    Views:
    330
    Tom Wingert
    Jan 12, 2006
  5. Replies:
    0
    Views:
    1,296
Loading...

Share This Page