Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Mar 23, 2012 05:10 AM by Dino He - MSFT
Mar 21, 2012 01:14 PM|LINK
I am developing a web application using MVC,
I have a web setup project for installing it to my localhost.
Now what I want is to create an EVENT SOURCE ( where I will later on log using my website ) using this very setup.
Is this possible ?
Please help me on this,
I have been following this link
As I earlier tried creating an EVENT SOURCE programmatically but my web app threw security exceptions, similar to the error the user in the post
System.Security.SecurityException when writing to Event Log was getting.
Mar 23, 2012 05:07 AM|LINK
Do you means you want to create a event log, but get the security excption?
Mar 23, 2012 05:10 AM|LINK
From MSDN: "Applications that run using the Network Service identity can write to the event log by using existing event sources, but they cannot create new event sources because of insufficient registry permissions."
"If the Source for the event log associated with the EventLog instance does not exist, a new event source is created."
So looks like your event log source doesn't exist, and it's trying to create a new event log source using the Network Service User (which requires writing to the registry, so wont work).
"To enable your ASP.NET application to write to the event log using an event source that does not already exist, you have two options:"
* Create new event sources at application install time
* Manually create new event source entry in the registry.
So, need to create the log outside of the application (you can't do it programatically with this user. Do it either manually, or create a simple command line app to simplify installation).
For full details:
Personally I'd recommend that you don't alter the net user permissions, but rather create the log source outside of the web app. My preference is in a console app (which will take you about 5mins to write, and which you can also use to prep other machines).
Start a new console app in VS.NET, and add the code to create the log sources. An example:
Then just run the console app from the cmd line, when logged in with appropriate permissions.
Hope it helpful.