初始化 Nlog 事件日志目标时出现安全异常
我在 IIS 和 Windows Server 2003 上托管的 ASP.NET 应用程序中使用 NLog。当我在开发计算机上运行代码时,一切正常。但是当我将代码部署到服务器时。 NLog目标的初始化会导致安全异常:
Security Exception 描述:应用程序试图执行安全策略不允许的操作。要授予此应用程序所需的权限,请联系您的系统管理员或在配置文件中更改应用程序的信任级别。
Exception Details: System.Security.SecurityException: Requested registry access is not allowed.
源错误:
当前 Web 请求执行期间生成未处理的异常。有关异常来源和位置的信息可以使用下面的异常堆栈跟踪来识别。
堆栈跟踪:
[SecurityException:请求的注册表 不允许访问。]
System.ThrowHelper.ThrowSecurityException(异常资源 资源)+51
Microsoft.Win32.RegistryKey.OpenSubKey(字符串 名称,布尔值可写)+7462217
System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData 源数据)+366
NLog.Targets.EventLogTarget.CreateEventSourceIfNeeded() +637 NLog.Targets.EventLogTarget.InitializeTarget() +40 NLog.Targets.Target.Initialize() +264 NLog.Config.LoggingConfiguration.InitializeAll() +233
有人知道我应该做什么才能给予应用程序适当的许可吗?谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,我明白了。网络服务帐户无权读取/写入事件日志。这就是抛出异常的原因。
Okay, I got it. Network Service account does not have permission to read/write the event log. That's why the exception thrown.
我已经以管理员身份运行了一次应用程序,以在
EventLog
中创建适当的规则。I have run my application once as administrator to create the appropriate rules in the
EventLog
.