Enterprise Library滚动平面文件跟踪侦听器的问题

时间:2012-07-10 15:48:34

标签: exception-handling enterprise-library

我正在使用Enterprise Library滚动平面文件跟踪侦听器将我的应用程序错误记录在单个文本文件中。但是,我观察到它创建了多个文件,并附加了一系列数字而不是登录到一个文件。

请参阅我的配置设置,让我知道是否需要进行任何更改

<listeners>
  <add name="Rolling Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=1234abccc"
    listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=1234abccc"
    fileName="AppError.log" formatter="Text Formatter" filter="Error" />
</listeners>


<formatters>
  <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=1234abccc"
    template="Timestamp: {timestamp}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;Priority: {priority}{newline}&#xA;EventId: {eventid}{newline}&#xA;Severity: {severity}{newline}&#xA;Title:{title}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Thread Name: {threadName}{newline}&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xA;Extended Properties: {dictionary({key} - {value}{newline})}"
    name="Text Formatter" />
</formatters>

<categorySources>
  <add switchValue="All" name="General">
    <listeners>
      <add name="Rolling Flat 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 Flat File Trace Listener" />
    </listeners>
  </errors>
</specialSources>
<exceptionHandling>
<exceptionPolicies>
  <add name="Application Policy">
    <exceptionTypes>
      <add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=1234abccc"
        postHandlingAction="NotifyRethrow">
        <exceptionHandlers>
          <add name="Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=1234abccc"
            logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
            formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
            priority="0" />
        </exceptionHandlers>
      </add>
    </exceptionTypes>
  </add>
</exceptionPolicies>

1 个答案:

答案 0 :(得分:2)

将数字附加到日志文件的原因是因为它检测到文件已存在且滚动平面文件跟踪侦听器增加文件编号。将 rollFileExistsBehavior 设置更改为覆盖,以确保您指定的文件被覆盖。