2

使用 Enterprise Library 5.0 日志记录时,我遇到了不稳定的日志记录。

问题在于托管在 IIS (7.5) 中的 WCF 4.0 应用程序,该应用程序在负载平衡配置的 Windows 2008 R2 服务器上运行。我正在使用 Unity (2.0) 进行依赖注入。我已将库配置为记录到滚动文本文件。该应用程序使用 AppFabricCache。

似乎在重新启动托管服务的 Web 应用程序后的前几次调用中记录成功。此后,看不到进一步的日志记录。我要么在配置中出错,要么在将输出写入/刷新到文本文件时可能存在一些争用。我了解 Logging 类以线程安全的方式运行。

下面是配置文件的相关部分。任何想法表示赞赏。谢谢。

<loggingConfiguration name="loggingConfiguration" tracingEnabled="true" defaultCategory="General">
    <listeners>
       <add name="Rolling File Trace Listener"
          type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
          fileName="d:\SOMEPATH\Logs\trace.log"
          formatter="Text Formatter"
          header="" footer=""
          timeStampPattern="yyyy-MM-dd hh:mm:ss.fff"
          traceOutputOptions="None"
          maxArchivedFiles="2000"
          rollFileExistsBehavior="Increment" rollInterval="Day" rollSizeKB="1024" />
    </listeners>
     <formatters>
        <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
         template="{timestamp(yyyyMMdd HH:mm:ss.fff)} - {message}"
         name="Text Formatter" />
     </formatters>
    <categorySources>
      <add switchValue="All" name="General">
        <listeners>
           <add name="Rolling File Trace Listener" />
        </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="Rolling File Trace Listener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>  
4

2 回答 2

2

您应该做的一件事是将其更改errors specialSource为不使用滚动文件跟踪侦听器。它应该使用另一个侦听器,例如FlatFileTraceListeneror EventLogTraceListener

我对正在发生的事情的猜测是写入日志条目时发生错误(可能是尝试滚动的权限问题)。但是您在日志中看不到任何内容,因为错误源设置为使用刚刚失败的相同侦听器,因此错误的记录也失败了。

于 2011-09-08T17:26:21.913 回答
0

感谢 Turzo,我重新配置以将错误记录到平面文件。然后我能够看到错误消息的详细信息。部分错误消息是拒绝访问。部分原因与找不到文件路径/格式不正确有关。事实证明,TimeStampPattern 指定不正确,因为它不会生成可接受的文件名格式。我将其更改为: timeStampPattern="yyyyMMdd_hhmm" 现在生成了滚动文件。

于 2011-09-11T20:00:59.277 回答