The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

import-bot (20211) [Avatar] Offline
[Originally posted by dansab]

I created an Web Application called Universitaria.
Inside it, I want to use your class MsgLog, written to log all the errors,
which are visible in EventLog:
namespace Universitaria
public class MsgLog
public MsgLog(string errMsg)
DateTime now = DateTime.Now;
errMsg = String.Format("{0} : {1}", now, errMsg);
EventLog log = new EventLog("Application",".","Universitaria");
log.WriteEntry(errMsg, EventLogEntryType.Error);
You remember your chapter 4, Listing 4.8... smilie

But when I instantiate an object of this class INSIDE my web application, I
receive the following error (Security Exception):

Security Exception
Description: The application attempted to perform an operation not allowed by
the security policy. To grant this application the required permission please
contact your system administrator or change the application's trust level in
the configuration file.

Exception Details: System.Security.SecurityException: Requested registry
access is not allowed.

Source Error:
Line 12: errMsg = String.Format("{0} : {1}", now, errMsg);
Line 13: EventLog log = new EventLog("Application",".","Universitaria");
Line 14: log.WriteEntry(errMsg, EventLogEntryType.Error);//here is raised except
Line 15: }
Line 16: }
Source File: c:inetpubwwwrootuniversitariamsglog.cs Line: 14
Stack Trace:
[SecurityException: Requested registry access is not allowed.]
Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable) +473

I used caspol to set my application to a full trust level, but the problem
remains... What is the remedy (if you know one)? I don't want to use an XML
file inside my application and append to it all error messages. I think is
more elegant the solution with EventLog in EventViewer. I have Administrator
privileges on my computer. your Poker application writes error messages, so I
don't know what is the problem in MY case.
import-bot (20211) [Avatar] Offline
best regards
[Originally posted by dansab]

and, Best regards,
import-bot (20211) [Avatar] Offline
Re: Question to Fergal Grimes . Security Exception!
[Originally posted by ekinated]


The problem is that the account that ASP.NET runs under does not have the
correct permissions to modify the registry entries necessary to create a new
Event Log Source (in your case for "Universitaria").

One possible solution is to write a quick console application that logs a
"test" event to the Event Log (using the "Universitaria" event log source) and
then run it. Assuming you run it under the guise of a user with enough
permissions to make registry modifications, your event log source should be
created and you'll be able to log events using the new event source in your
web pages from then on.
import-bot (20211) [Avatar] Offline
Re: Question to Fergal Grimes . Security Exception!
[Originally posted by fgrimes]

Hi Dan,

Eric's diagnosis sounds good to me. (Thanks, Eric.) Please let us know if it

import-bot (20211) [Avatar] Offline
Re: Question to Fergal Grimes . Security Exception!
[Originally posted by dansab]

Yes, is OK.