I have developed a quite simple ASP.NET
web application that reads the system event logs entries.
When I am debugging or running it from VS 2017 (hosted in IIS Express) I am able to read the log entries without any issue.
Once I deploy/publish this asp.net web app on IIS 8
and try to read the system event log entries it doesn't work.
If I check the event viewer I get something like this (translated from Spanish) :
System.InvalidOperationException: Unable to open the Application record on the computer Windows has not provided an error code. ---> System.ComponentModel.Win32Exception: Access Denied"
I have read other questions but are related to writing in the event log. I'm just interested in being able to read system event log entries. I guess it has something to do with permissions but I don't know which permissions I would have to set and to which user.
Here there are some parts of my code:
System.Diagnostics.EventLog eventLog = new EventLog(LogName, machineName);
...
EventLogEntryCollection entries = eventLog.Entries; //This is where I get the Acces denied Exception.
Answer (workaround)
It may be not the proper way to solve it (for security issues), but as it is for the moment an internal application, I have made it work like this. That is, read the log Events from several remote machines through the use of impersonate
on my web.config file
<system.web>
<identity impersonate="true" userName="SomeDomainUserWithRigtsToread" password="itsPwd"/>