Write eventlog while using impersonation

878 views Asked by At

For some reason when I use the impersonate option in web.config. Everything is fine, but one problem obsesses me that is the following error occurs while using System.Diagnostics.TraceSource to write to the eventlog:

System.Web.HttpUnhandledException (0x80004005): 
Exception of type 'System.Web.HttpUnhandledException' was thrown. 
---> System.ComponentModel.Win32Exception (0x80004005): 
Access is denied at System.Diagnostics.EventLogInternal.InternalWriteEvent(UInt32 eventID, UInt16 category, EventLogEntryType type, String[] strings, Byte[] rawData, String currentMachineName) 
at System.Diagnostics.EventLogInternal.WriteEvent(EventInstance instance, Byte[] data, Object[] values) 
at System.Diagnostics.TraceSource.TraceEvent(TraceEventType eventType, Int32 id, String message)

Anyone give me some suggestion on this? Thanks in advance.

1

There are 1 answers

0
BozoJoe On

The User who is being impersonated doesn't have permissions to write to the eventlog.

I suggest you use a TraceListener that any user has write access to (like a file with a directory that's wide open.