0
votes

edI have C# ASP.NET 4.5 Webform application and use the following code:

 if (!EventLog.SourceExists(sSource)) EventLog.CreateEventSource(sSource, sLog);

     EventLog.WriteEntry(sSource, message, level);

Since the first line was failing I created HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\IDDISLOG in registry

I get the following exception on WriteEntry Method:

 Cannot open log for source 'IDDISLOG'. You may not have write access. 

Searched other similar questions but none worked for me.

Here is what I have done so far:

Added "Network service" to the project file folder

Added Network service to and gave it full access. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog

Added Nertwork service to and gave it full access.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Security

Checked and saw w3wp.exe *32 process runs with User Name ASP.Net v4.0.

So added ASP.Net v4.0 to

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog

Still, error remains

2
Do you have a log container called IDDISLOG in your event viewer? I am assuming if you do it is a custom one as a google search for IDDISLOG returns nothing. - Sorceri
does this event source IDDISLOG already exist on the machine? If not, you need to create it first, for which you need administrator permissions, which your application should not have. If that's the case it's hopefully just a bit of housekeeping when you install the application. - ADyson
IDDISLOG is name of the source Im trying to create in Registry. So I pass sSource="IDDISLOG" - S Nash

2 Answers

0
votes

Your user account may not have sufficient privileges to create an event source, which only administrator accounts can do. If you can log in as an administrator, either run your code again or add a folder here: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\IDDISLOG

That should allow your application to write to the event log with that source. You may need to configure the actual registry entry further to suit your needs.

0
votes

In IIS (Windows server), you should change de identity used by de app pool, so the new identity has permission to write to the event log. Select the app pool and advanced settings. then edit and insert a custom account, althoug local system will suffice. If you use a custom account be sure not to use a user whose password is going to expire, because when it happens logging to event log will fail.