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."
And...
"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).
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:
vaibhav_shah...
Member
402 Points
113 Posts
Creating event log when installing the web setup
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 http://msdn.microsoft.com/en-us/library/ms998320.aspx#paght000015%5Feventlogaccess
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.
Click Here For More Answers
SonicMan
Participant
1472 Points
228 Posts
Re: Creating event log when installing the web setup
Mar 23, 2012 05:07 AM|LINK
Hi
Do you means you want to create a event log, but get the security excption?
Dino He - MS...
Star
8068 Points
1023 Posts
Microsoft
Re: Creating event log when installing the web setup
Mar 23, 2012 05:10 AM|LINK
Hi
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."
And...
"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:
http://msdn.microsoft.com/en-us/library/ms998320.aspx#paght000015_eventlogaccess
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:
http://www.dotnetspider.com/resources/23593-Create-Event-log-VB-NET.aspx
Then just run the console app from the cmd line, when logged in with appropriate permissions.
Hope it helpful.
Regards.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework