Write to Windows Event Log

  • Thread starter Thread starter -Steve-
  • Start date Start date
S

-Steve-

I have code that calls System.Diagnostics.EventLog.WriteEntry to write
exceptions to the windows app event log. However by default you have to be
an admin to write to the application event log.

Is the best way to enable this to give write permissions to
C:\WINDOWS\system32\config\AppEvent.evt or is there a better way to handle
this?

Steve
 
Maybe you could use impersonation to switch to an admin user to write to
the event log. Haven't done this before, but it seems like it would
fit. Not sure what kind of side-effects it might have, but it seems
like you could impersonate an admin, write the log entry, and then let
go of the impersonated admin.

Look into System.Security.Principal.WindowsIdentity.Impersonate

--Brian
 
Back
Top