Problem in accessing/writing to EventLog

2019-04-10 01:10发布

I'm working with some old code (and frankly I don't know half of what it does) trying to move it over to IIS7.

One of the problems I see is that I get this error:

[SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.]

If I go manually to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Security and set that key's (Security) permission to let "Everyone" have full access this goes away no problem. But obviously that's not the optimal solution.

Anyone know of a better way to remove this exception?

2条回答
▲ chillily
2楼-- · 2019-04-10 01:39

One way to fix this is to run a simple console application under full trust that writes a single EventLog entry under the offending source name. You'll have to do this once for each server.

From that moment on, you should be able to log under that source name. (at least that's been my observation.) It's just creating an unknown source that you cannot do from under ASP.NET, logging to an existing source should not be a problem.

Question is: do you know the source name? If you don't, temporarily granting access to Everyone, wait for a log message, and removing Everyone should also work.

The official Microsoft way is to create an installer which registers an Event Log Source.

查看更多
来,给爷笑一个
3楼-- · 2019-04-10 01:41

From this thread:

EventLog.CreateEventSource() method attempts to search Event Sources under all event logs, not just the event log for which you want to create the source. There are two solutions to this. The first, easiest, and most insecure, is just to give read/write access to all event logs for the ASP.NET account.

Code and other solutions are also provided.

查看更多
登录 后发表回答