我在 IIS 和 Windows Server 2003 上托管的 ASP.NET 应用程序中使用 NLog。当我在我的开发机器上运行代码时,一切正常。但是当我将代码部署到服务器时。 NLog目标的初始化会引发安全异常:
安全异常 说明:应用程序试图执行安全策略不允许的操作。要授予此应用程序所需的权限,请联系您的系统管理员或更改配置文件中应用程序的信任级别。
Exception Details: System.Security.SecurityException: Requested registry access is not allowed.
来源错误:
在执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常来源和位置的信息。
堆栈跟踪:
[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
有没有人知道我应该怎么做才能给予应用程序适当的许可?谢谢!
最佳答案
好的,我明白了。网络服务帐户没有读取/写入事件日志的权限。这就是抛出异常的原因。
关于c# - 初始化 Nlog 事件日志目标时出现安全异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3501191/