Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entreprise Library Rolling flat file is not rolling

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>

like image 334
Pedro Pereira Avatar asked Jul 26 '11 14:07

Pedro Pereira


1 Answers

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.

like image 103
Grigori Melnik Avatar answered Oct 17 '22 23:10

Grigori Melnik