views:

623

answers:

2

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  A: 

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.

Ruben
Two questions:1) I don't see a log message when granting access to Everyone. That's what weird.2) How do I register an Event Log Source from the installer (or a custom vb script for that matter)?
royrules22
Like Rob Elliott says `EventLog.CreateEventSource()`. It's possible that this is what the ASP.NET is doing on its own before it even starts logging.
Ruben
I tried making a vbscript that does this:Imports SystemImports System.DiagnosticsEventLog.CreateEventSource "AppSource", "Application"but i get an error saying:Type mismatch: 'Imports'What in the world does this mean?
royrules22
^ the above code has line breaks but the formatting in this just got ruined
royrules22
As for creating an installer: follow MSDN on creating a service + installer + setup. Add the EventLogInstaller to your installer designer surface (you'll need to add it explicitly to your toolbox with "Choose items...") and remove the ServiceInstaller and ServiceProcessInstaller (you don't need to install a service, right?).Just calling `EventLog.CreateEventSource()` from a trusted environment is way simpler.
Ruben
We have an installer that I have to use. It basically runs vbs files via CScript.exe hence my code above. I'm stuck as to why it's complaining about the damn imports statement.
royrules22
Don't use VBScript. Create a VB.NET console application. You cannot use VBScript to configure an EventSource for .NET apps, because they require a special registration. If you don't you'll have a hard time reading the event log entries.
Ruben
Thanks for all the help. Really appreciate it!
royrules22
A: 

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.

Rob Elliott