Issue with EventLog under Vista/7 and Dev Web Server
Since we upgraded all of our developer boxes to Windows 7, we've had trouble executing our web projects locally under Cassini.
I've seen this issue in Vista, too, I believe.
What happens is that any attempt to write to the event log running under Cassini results in an Win32Exception with the error message "The parameter isincorrect." So far, I can only get this code to run when running as an Administrator. I'm not sure why writing to the event log should require elevation, but it seems to.
Here's the code:
Public Class EventLogger
Public Const EVENTLOGGER_SOURCE As String = "My Web App"Public Shared Sub CheckLogSource()
If Not System.Diagnostics.EventLog.SourceExists(EVENTLOGGER_SOURCE) Then
System.Diagnostics.EventLog.CreateEventSource(EVENTLOGGER_SOURCE, "Application")
End If
End SubPublic Shared Sub LogInformationalMessage(ByVal message As String)
System.Diagnostics.EventLog.WriteEntry(EVENTLOGGER_SOURCE, message, System.Diagnostics.EventLogEntryType.Information)
End SubEnd Class
Calling LogInformationalMessage with any value causes the exception.
To get around this, for the time being, I've commented out the call to WriteEntry...but I don't think that's a long term solution. Does anybody know what I need to do to get this working?
Answers
- Hi,
Here are two solutions for you, hope they can help:
1. Modify the registry permissions of the target event source, the path is HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\'Your evnet log name' .
2. Modify the LogInformationalMessage () method, impersonate an administrator to write event logs. CodeFx has a demo about how to impersonate a user, you can find the code in 'Security ' solution -> 'VBImpersonateUser ' project.
Thanks,
Eric
Please remember to mark helpful replies as answers and unmark them if they provide no help.- Marked As Answer byeryangMSFT, ModeratorWednesday, November 11, 2009 9:33 AM
All Replies
- Hi,
Here are two solutions for you, hope they can help:
1. Modify the registry permissions of the target event source, the path is HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\'Your evnet log name' .
2. Modify the LogInformationalMessage () method, impersonate an administrator to write event logs. CodeFx has a demo about how to impersonate a user, you can find the code in 'Security ' solution -> 'VBImpersonateUser ' project.
Thanks,
Eric
Please remember to mark helpful replies as answers and unmark them if they provide no help.- Marked As Answer byeryangMSFT, ModeratorWednesday, November 11, 2009 9:33 AM
I'm not sure how to do #1. My user has full control on the that registry key. What user is Cassini running as?
- Hi,
Do you mean Cassini Web Server, if yes, you will get better response at http://forums.asp.net
Anyway, how about solution #2, is that work?
Thanks,
Eric
Please remember to mark helpful replies as answers and unmark them if they provide no help. - For some reason I wasn't getting e-mail notifications of responses to this thread so it fell off my radar.
To bring some closure to this: using the Impersonate function in CodeFX to run the code as my local user worked. Seems you still have to be an administrator to actually create the log source, but once it's there, you can use Impersonate to write to the log.
I'm off to the ASP.NET forums to inquire about other solutions that don't require embedding passwords, even in debug mode, in our code.


