加载log4net时出错

时间:2014-06-03 19:43:45

标签: c# log4net

我们的应用程序包含一个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在抱怨什么。

1 个答案:

答案 0 :(得分:1)

您需要特殊(提升)权限才能写入应用程序日志(因为您使用的是写入Windows事件记录器的EventLogAppender)。

检查当前用户的权限。