如何使用滚动平面文件跟踪侦听器重命名日期文件与修改日期

时间:2012-06-28 03:49:28

标签: file c#-4.0 logging enterprise-library-5

我的愿望输出是,如果“rolling.log”文件是在26-06-2012,第二天(27-06-2012)创建和修改的,那么该文件应该用“rolling-26-06-2012..log”重命名。 。现在输出是“rolling-27-06-2012.log”文件。

以下是我在web.config文件中的当前日志记录设置。

< * loggingConfiguration name =“”tracingEnabled =“true”defaultCategory =“myTestLog”>

<*listeners>

  <*add name="Rolling Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    fileName="C:\Project\Others\Testing\testMSLogging\rolling.log"
    formatter="Text Formatter" rollFileExistsBehavior="Increment"
    rollInterval="Minute" rollSizeKB="50" timeStampPattern="yyMMdd"
    filter="Information" />

  <*add name="Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    fileName="C:\Project\Others\Testing\testMSLogging\testMSLogging\trace.log"
    formatter="Text Formatter" filter="Error" />
</listeners>

<*formatters>

  <*add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    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="myTestLog">
    <*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="Flat File Trace Listener" />
    </listeners>
  </errors>
</specialSources>

请有人帮助我。非常感谢。

1 个答案:

答案 0 :(得分:0)

不幸的是,这是它在企业库中的工作方式。其默认平面文件滚动背后的理念是它记录FILE.LOG中的所有输出,当滚动事件发生时,它将其重命名为FILE-ROLL-NAME.LOG并创建一个新的FILE.LOG 如果您需要不同的行为,您可能需要创建自己的日志记录跟踪侦听器或使用其他工具,如log4net。