企业库日志记录未从ASP.NET登录到事件日志

Cos*_*sta 12 .net asp.net logging enterprise-library

我花了一天时间尝试使Ent Lib Logging工作并将任何内容记录到数据库或事件日志中.我有一个具有相同Ent Lib配置的Web应用程序和控制台应用程序,但只有控制台应用程序能够登录到事件日志.我尝试了所有权限,但我不知道我在做什么 - 哪些服务应该有什么.这是行不通的!

我读过这样的文章 http://imar.spaanjaars.com/275/logging-errors-to-the-event-log-in-aspnet-applications ,我想尝试给ASPNET帐户这些权限.我使用Windows 7,我找不到ASPNET用户帐户.那它在哪里?

这是从Ent Lib实用程序自动生成的配置文件,它仅适用于App.config,而不适用于web.config

<loggingConfiguration name="Logging Application Block" tracingEnabled="true"
    defaultCategory="General" logWarningsWhenNoCategoriesMatch="true"
    revertImpersonation="false">
    <listeners>
      <add source="Logger" formatter="Text Formatter" log="Application"
        machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Formatted EventLog TraceListener" />
    </listeners>
    <formatters>
      <add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
        type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Text Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="General">
        <listeners>
          <add name="Formatted EventLog TraceListener" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events" />
      <notProcessed switchValue="All" name="Unprocessed Category" />
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Formatted EventLog TraceListener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
Run Code Online (Sandbox Code Playgroud)

Ran*_*ica 4

我相信在 IIS7(我假设您正在使用)下,应用程序池将在 NETWORK SERVICE 下运行

您可以尝试将 NETWORK SERVICE 完全控制权授予该注册表项HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application
(不建议!)

或者,您可以向 EVERYONE 授予完全控制权HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application,记录消息,然后恢复该更改。设置密钥后,您将不需要写入注册表的权限。

或者您可以预先手动配置所需的注册表项以避免权限问题:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application\Logger]
"EventMessageFile"="c:\\WINNT\\Microsoft.NET\\Framework\\v2.0.50727\\EventLogMessages.dll"
Run Code Online (Sandbox Code Playgroud)


只是对此答案的更新,根据MSDN:“要在 Windows Vista 及更高版本或 Windows Server 2003 中创建事件源,您必须具有管理权限”。

  • 我认为授予网络服务对注册表的完全访问权限是一个坏主意。 (2认同)