iis-7 - 使用非管理员帐户的 log4Net 事件日志权限问题

标签 iis-7 log4net event-log

这可能不是 SiteCore 本身的问题,但为了完整起见,我已将其包含在内。我使用应用程序池的自定义标识在 IIS7 下运行 sitecore 6.3。我无法让 Sitecore 将其日志信息(使用默认的 log4net 设置)写入事件日志。我遵循了这里的建议:http://logging.apache.org/log4net/release/faq.html#Why%20doesn%27t%20the%20EventLogAppender%20work?虽然当我使自定义身份成为管理员组的成员时它工作正常,但我需要找到一种方法让它在没有这样的安全黑客的情况下在生产中工作。

奇怪的是,我有一个 MSI 安装它(在作为管理员组成员的帐户下运行)并在事件日志中为我创建正确的注册表项,但尽管如此,我仍然收到以下错误我使用自定义身份运行应用程序(它不是管理员成员)。

log4net:ERROR DOMConfigurator: 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)
at System.Diagnostics.EventLog.DeleteEventSource(String source, String machineName)
at log4net.Appender.EventLogAppender.ActivateOptions()
at log4net.Repository.Hierarchy.DOMHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
The Zone of the assembly that failed was:
MyComputer
log4net:ERROR DOMConfigurator: Appender named [EventLogAppender] not found.

认为我可以将其缩小到注册表权限问题,我授予每个人对以下注册表项和子项的完全权限,但它也不起作用:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog
自定义身份是以下组的成员:
  • 事件日志阅读器
  • IIS_USERS
  • 性能监视器用户

  • 我也看到了 following question这似乎问同样的事情。 Microsoft 文章似乎暗示事件日志上的 ACL 可能存在问题,并提供了有关如何更改 SSDL 的示例,但如果可能,我宁愿避免这种情况。

    编辑:
    我有另一台服务器正在运行,其中日志填充得很好。自定义身份是管理员的成员,所以我撤销了它并重新启动,试图故意破坏它,但我不能。两个盒子上的配置和用于运行创建注册表项的 MSI 的标识相同。已在两者上运行 procmon(在执行 IISReset 并再次启动应用程序池之后)以检查注册表事件。奇怪的是 - 在工作的盒子上,你在错误的地方(应用程序和不同的自定义事件日志“MyCompany”)获得了 477 个未找到我的事件源的记录。它记录的位置“MyCompany\MyCompany.SiteCore”没有命中。虽然在损坏的盒子上,它似乎确实在请求读取正确的 key (尽管只有 6 次),但随后您会收到 Log4Net 注册表访问错误。

    最佳答案

    据我了解,EventStores 存储在注册表中,因此您只需要对注册表的写权限即可创建或删除 EventStore。这通常只需要一次,大多数应用程序将其创建为安装过程的一部分,因此应用程序在正常执行期间不需要以管理员身份运行。
    但是,您的错误消息(在问题中)包括方法 删除事件源 我会从中推断/猜测 EventSource 确实存在,但在某些方面是错误的。因此,这可能当前已注册为写入名为 MyCompany 的事件日志,而您现在正尝试将其更改为“MyCompany\MyCompany.SiteCore”,这需要您删除旧的事件源并创建一个新的事件源。
    因此,听起来您的安装例程正在创建与您的应用程序实际使用的 EventSource 不同的 EventSource。
    如果这没有帮助,那么我建议启用 internal logging for Log4net (但显然不是事件日志)这可能会为您提供更多信息。
    对注册表项授予完全权限是不够的。
    根据 Microsoft

    To create an event source in Windows Vista and later or Windows Server 2003, you must have administrative privileges.

    The reason for this requirement is that all event logs, including security, must be searched to determine whether the event source is unique. Starting with Windows Vista, users do not have permission to access the security log; therefore, a SecurityException is thrown.

    Starting with Windows Vista, User Account Control (UAC) determines the privileges of a user. If you are a member of the Built-in Administrators group, you are assigned two run-time access tokens: a standard user access token and an administrator access token. By default, you are in the standard user role. To execute the code that accesses the security log, you must first elevate your privileges from standard user to administrator. You can do this when you start an application by right-clicking the application icon and indicating that you want to run as an administrator.

    关于iis-7 - 使用非管理员帐户的 log4Net 事件日志权限问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8447948/

    相关文章:

    apache - IIS 和 Apache (WAMP) 运行

    asp.net - 无法清除 ASP.NET 缓存

    .net - 人们在记录时捕获的字段 - log4net

    azure - 在 Azure 中每天记录一个文件

    c# - 设置 Log4Net 以记录类库的输出

    .htaccess - 删除 htaccess 中的特定查询字符串键/值对(但保留其他完整)

    windows - IIS 管理器正在运行,但 Window 未显示在 Windows 7 中

    security - PowerShell 安全日志

    wix - 如何使用 WiX 创建 .NET 事件日志源

    email - 通过电子邮件通知对多台计算机进行日志监控 - 按事件 ID 过滤