Writing to EventLog Error (not ASP.Net)

Writing to EventLog Error (not ASP.Net)

Post by Mike » Fri, 20 Jun 2008 23:09:50


I created a simple console app that registers and event source and
write a test entry. The event source is registered properly but when
I go to write the entry I get the "Cannot open log file for source
'{0}'" error. (this occurs in Windows XP_

An inner exception says "The handle is invalid"

I have traced this down to EventLog.OpenForWrite(machineName) on this
line of code:

writeHandle =
SafeEventLogWriteHandle.RegisterEventSource(currentMachineName,
sourceName);
if (writeHandle.IsInvalid) {
Win32Exception e = null;
if (Marshal.GetLastWin32Error() != 0) {
e = SharedUtils.CreateSafeWin32Exception();
}
throw new
InvalidOperationException(SR.GetString(SR.CantOpenLogAccess,
sourceName), e);
}

The user context is an administrator on the machine. The error
suggests a security issue but it appears to be something else.

I've tested the same code in Windows Vista, and it fails before this
line of code. That error message points to a security problem,
probably UAC.

Here is a snippet of my code that produces this error:

EventSourceCreationData eData = new
EventSourceCreationData(sourceName, logName);
eData.MachineName = (machineName ?? ".");

EventLog.CreateEventSource(eData);

EventLog el = new EventLog(eData.LogName,
eData.MachineName, eData.Source);
el.Wri *** try(testEvent, EventLogEntryType.Information);

I'm stuck! Can anyone help?

Thanks,
Mike
 
 
 

1. "Requested registry access is not allowed" when writing to eventlog!

2. ASP not writing to Eventlog

I have a VB, ASP program running on IIS 6.0.
The VB ActiveX dll writes events to eventlog using the following line
of code:

App.LogEvent (Err.Number & " " & Err.Description & " Source: " &
Err.Source)

The above dll is complied and is called in ASP page as follows:

if err.number <> 0 then

set myObj = server.CreateObject("ErrorHandler.Class1")
myobj.WinNTLog err.number, err.description, err.source, errmsg, 1
set myobj = nothing

End if

The above code works fine when I run IIS under integrated account. I
pass my administrative crednetials on the server.

But when I run the above under anonymous account, then nothing gets
logged on to the eventlog. Any idea what is going on?

Thanks,
Chanda.



I tried to implement your code in my project at
http://www.yqcomputer.com/

It works totally fine when I run IIS6.0 in integrated environment. But
when I use anonymous account, then nothing gets logged in eventlog.

3. HELP! - App.LogEvent Not Writing to EventLog

4. Error: Could not find a part of the path / Reading and Writing to files in ASP.Net

5. Not able to run ASP.Net applications-Error in ASP.Net

6. Error.Error..Error...web server is not running asp.net 1.1

7. Read EventLog - position to newest record / end of EventLog ???

8. Difference between System eventlog and those created by EventLog c

9. IIS6 EventLog and ASP.NET

10. Remove EventLog without EventLog.Delete

11. EventLog access through ASP.Net app

12. Analysis Server Error: File error [Write error] There is not enough space on the disk