【发布时间】:2014-06-03 19:43:45
【问题描述】:
我们的应用程序包含一个 Windows 服务,我们可以将其作为控制台应用程序运行以进行调试和测试。它使用 log4net 将日志条目写入 Windows 事件日志。
今天早上,我在我们的开发机器上安装了我们的应用程序,然后将其卸载。自从我卸载它后,每当我将服务作为控制台应用程序启动时,我都会收到以下错误消息:
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender
[EventLogAppender] of type [log4net.Appender.EventLogAppender].
Reported error follows.
System.Security.SecurityException: Requested registry access is not allowed.
at Microsoft.Win32.RegistryKey.OpenSubKey
(String name, Boolean writable)
at System.Diagnostics.EventLog.GetEventLogRegKey
(String machine, Boolean writable)
at System.Diagnostics.EventLog.FindSourceRegistration
(String source, String machineName, Boolean readOnly, Boolean wantToCreate)
at System.Diagnostics.EventLog.DeleteEventSource
(String source, String machineName)
at log4net.Appender.EventLogAppender.ActivateOptions()
at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender
(XmlElement appenderElement)
The Zone of the assembly that failed was:
MyComputer
谁能指出我正确的方向来解决这个问题?请注意,事件记录似乎正在工作,所以我不清楚 log4net 抱怨什么。
【问题讨论】:
-
您是否尝试以 administrator 身份运行您的应用程序?
-
无论运行该服务的用户帐户如何,都无法访问 Log4Net 尝试访问的任何注册表项。用户是谁,关键是什么我不知道。但是通过服务和进程监视器应该很容易找到。