Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Security Exceptions while initializing Nlog event log target

I'm using NLog in my ASP.NET application hosted on IIS and Windows server 2003. When I run the code on my develop machine, everything is Okay. But when I deployed the code to the server. The initialization of NLog target will cause an 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:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[SecurityException: Requested registry access is not allowed.]
System.ThrowHelper.ThrowSecurityException(ExceptionResource resource) +51
Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable) +7462217
System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData sourceData) +366
NLog.Targets.EventLogTarget.CreateEventSourceIfNeeded() +637 NLog.Targets.EventLogTarget.InitializeTarget() +40 NLog.Targets.Target.Initialize() +264 NLog.Config.LoggingConfiguration.InitializeAll() +233

Does anyone when what should I do in order to give the application proper permission? Thanks!

like image 432
Roy Avatar asked Dec 12 '25 00:12

Roy


1 Answers

Okay, I got it. Network Service account does not have permission to read/write the event log. That's why the exception thrown.

like image 165
Roy Avatar answered Dec 13 '25 14:12

Roy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!