代码之家  ›  专栏  ›  技术社区  ›  Orson

如何使用C#写入windows事件日志(我遇到了某种错误)?

  •  1
  • Orson  · 技术社区  · 16 年前

    .
    .
    .
    //Log exception to the event log
    if (!EventLog.SourceExists("PodaHIS")) {
        EventLog.CreateEventSource("PodaHIS", "Application");   
    }
    
    EventLog eventLog = new EventLog();
    eventLog.Log = "Application";
    eventLog.Source = "PodaHIS";
    eventLog.WriteEntry(error.ToString(), EventLogEntryType.Error);
    

    我还启用了对LOCALMACHINE\ASPNET的读取权限。

    作为回报,我得到:

    The source was not found, but some or all event logs could not be searched. Inaccesible logs: Security.
    

    有人知道为什么会这样吗?

    5 回复  |  直到 16 年前
        1
  •  3
  •   Orson    16 年前

    HKEY\U LOCAL\U MACHINE\System\CurrentControlSet\Services\EventLog

    “事件日志项读取权限的子项。之后,我重新启动了我的IIS。

        2
  •  1
  •   gingerbreadboy    16 年前

    这篇kb文章解释了为asp进程授予写入事件日志的正确安全权限所需的步骤。。。

    kb

        4
  •  0
  •   Rob Kent andersra    16 年前

    我认为在事件日志中创建源需要更高级别的访问。对安全日志的引用可能是巧合,它只是报告了这一可能的原因。如果您以管理员的身份进入并自己创建PodaHIS源,您可能会发现它可以对其进行写入。

        5
  •  0
  •   Regent    16 年前

    这 link 详细解释问题。