I need logging to:
- Rolling file, to avoid 1 big log file.
- CSV format for easier look up.
I can see the EntLib (5.0) has the Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener to log to a rolling log file.
To make the log entries look like a CSV row, I can change the Formatters.TextFormatter.Template to put double quote around the values, and also change the Listener’s Footer and Header to nothing, so they won’t be output.
Under normal circumstance, this would give me a well formed CSV file. However if a token value in the Template contain a double quote, this would not be escaped. Hence the log file become an invalid CSV file.
Is there any way to resolve this?
Is there any alternative solutions to this problem?
See http://msdn.microsoft.com/en-us/library/ff650608.aspx.
Turn out adding a custom formatter is not that hard, I added a CSVTextFormattter to only take care of massaging the message and extended properties, which works for me.
Notice I use the bult-in TextFormatter to do all the heavy lifting.
Sample Config:
The class is something like this: