2012-07-10 49 views
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> 

回答

2

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