【问题标题】:How can i rename the log file with Modified date by using Rolling Flat File Trace Listener如何使用滚动平面文件跟踪侦听器重命名具有修改日期的日志文件
【发布时间】:2012-06-28 03:49:28
【问题描述】:

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

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

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

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

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2019-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-09
      • 2011-01-19
      • 2012-06-02
      • 2015-11-18
      相关资源
      最近更新 更多