Problems writing to the Event Log

S

Scott Vercuski

Everyone,

I'm having trouble writing an event to the event log. Here is the
chunk of code I currently have.

-----------------------------------------------------------------------
Private Shared Function WriteErrorToLog(ByVal objError As
System.Text.StringBuilder, ByVal strSource As String) As Boolean
Dim objEL As New EventLog
Dim blnreturnvalue As Boolean

Dim Response As System.Web.HttpResponse
Response = System.Web.HttpContext.Current.Response

Try
If objEL.SourceExists(strSource) = False Then
objEL.CreateEventSource(strSource, "Application")
End If

objEL.Source = strSource
objEL.WriteEntry(objError.ToString(),
EventLogEntryType.Error)
blnreturnvalue = True
Catch ex As Exception
Response.Write("MSG: " & ex.Message & "<br>")
Response.Write("ST: " & ex.StackTrace & "<br>")
blnreturnvalue = False
End Try

Return blnreturnvalue
End Function
-----------------------------------------------------------------------

When I call this function I see the following error ...

MSG: Cannot open log for source {0}. You may not have write access.

I'm at a complete loss as to what's going on?? has writing to the
event log become such a chore now?? this is a little crazy ... I've
been at this for a day or so. I've tried switching the impersonate
setting (right now it's at false), permissions on the ASP.NET account,
the IUSR account etc ... I'm running out of ideas.

Thanks in advance for any assistance !

Scott Vercuski
(e-mail address removed)
 
G

Guest

I had same trouble couple of days ago...

2. A better way is to leave the processModel’s username set to machine and create the required registry entry yourself. Open the Registry editor and access the following key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application
Create a new key at this level by the user-def. name

Now within this key, add a new string value and set its name to EventMessageFile and set its value to: C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\EventLogMessages.dll

See it -> Chapter 4
http://www.techcontent.com/TG70315FAQ.htm
 
S

Scott Vercuski

Lauri,

Thank you for your reply. I read the Chapter 4 code but
unfortuantely it won't help with my problem. The "source" I'm using
is coming directly from the exception in a try catch block ... EX:

Dim objEL As New EventLog

Try
<CODE>
Catch ex as Exception
If objEL.SourceExists(ex.Source) = False Then
objEL.CreateEventSource(ex.Source, "Application")
End If
objEL.Source = ex.Source
objEL.WriteEntry(ex.StackTrace,
EventLogEntryType.Error)
end try

I'm using this to create a generic exception handler so the source
could technically be coming from almost anywhere. I'd rather not try
and write a dynamic registry entry generator for every source I
encounter.

Thank you again !
Scott Vercuski
(e-mail address removed)
 

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