1

Enterprise Library ローリング フラット ファイル トレース リスナーを使用して、アプリケーション エラーを 1 つのテキスト ファイルに記録しています。しかし、1 つのファイルにログインするのではなく、いくつかの一連の番号が追加された複数のファイルが作成されることを確認しています。

私の構成設定を見て、必要な変更を教えてください

<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>

4

1 に答える 1

2

ログファイルに番号が追加される理由は、ファイルがすでに存在することを検出し、ローリングフラットファイルトレースリスナーがファイル番号をインクリメントするためです。rollFileExistsBehavior設定をOverwriteに変更して、指定したファイルが確実に上書きされるようにします。

于 2012-07-11T05:03:42.117 に答える