Entreprise Library Rolling flat file is not rolling

僤鯓⒐⒋嵵緔 提交于 2020-01-13 10:27:29

问题


I'm trying to rotate log files, one per day of week and this configuration file is not working. If I change it to rotate instead of midnight to minute it only records one single file with one minute duration. No new files are being generated. Are there any known bugs of the latest version of entreprise library that focus on rolling flat files not working? Is there any problem with my current configuration? Thank you!

<loggingConfiguration name="" tracingEnabled="true" defaultCategory="General"
    revertImpersonation="false">
    <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=31bf3856ad364e35"
    listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    fileName="C:\EMS\logs\MobileMessagingServices.log" footer="" formatter="Text Formatter"
    header="" rollFileExistsBehavior="Increment" rollInterval="Midnight"
    rollSizeKB="100000" timeStampPattern="yyyy-MM-dd hh:mm:ss" maxArchivedFiles="7"
    traceOutputOptions="Timestamp, Callstack" filter="All" />
</listeners>
<formatters>
  <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    template="{timestamp} :: {category} :: {message}" 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">
    <listeners>
      <add name="Rolling Flat File Trace Listener" />
    </listeners>
  </allEvents>
  <notProcessed switchValue="All" name="Unprocessed Category">
    <listeners>
      <add name="Rolling Flat File Trace Listener" />
    </listeners>
  </notProcessed>
  <errors switchValue="All" name="Logging Errors &amp; Warnings">
    <listeners>
      <add name="Rolling Flat File Trace Listener" />
    </listeners>
  </errors>
</specialSources>


回答1:


I managed to reproduce your example.

It appears that your problem is in the time-stamp pattern. You use colon (:) as a delimiter for minutes and seconds; when the timestamp gets concatenated to the file name, that name doesn't get accepted because the colon is a reserved character. You don't see the error, since your 'errors' special source is also configured to use the Rolling Flat File Trace Listener.

Replace colon with space, dash, underscore or any other character which is valid for a file name and everything will work. Also, consider configuring a separate listener for the error category.

Also, since you chose rollFileExistsBehavior="Increment" and not "Overwrite", it will add a .1 suffix to each file. The suffix will not increment, since you are going to get a new file every second. You may want to remove ss from the time pattern or change the rollFileExistsBehavior.



来源:https://stackoverflow.com/questions/6831490/entreprise-library-rolling-flat-file-is-not-rolling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!