0

我想要的输出是,如果“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>

请任何人帮助我。非常感谢。

4

1 回答 1

0

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

于 2012-10-11T15:05:52.257 回答