I Want to configure Enterprise Library Logger to write to a file until it reaches a specified size.
After i reaches the specified size I would like it to do one of the following:
- Do roll the file (Delete old log lines and add new ones, not the clear the entire file).
- Keep the content in a file and clear the log file (keep only one backup file).
Currently I have configuration for one file that clears every time the file is full. This is my configuration
<listeners>
<add fileName="C:\ProgramData\Hamoub\Log\TransferLog.log"
formatter="Text Formatter"
header="----------------------------------------"
rollFileExistsBehavior="Overwrite"
rollSizeKB="100000"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
traceOutputOptions="None"
filter="All"
type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Rolling Flat File Trace Listener"/>
</listeners>
Thanks for your help
So, There is no way to do this in configuration alone.
My solution was to add FileSystemWatcher on the output folder, and whenever a new file is created there, I checked if deletion is needed.
I have ordered the folder files before deletion so only old files will be deleted (keeping the current and previous log files.
The Watcher Code:
The handler Code:
Hopefully, this post will help someone who looks for such solution
Barak Hamou