Semantic logging - Log to existing flat file

Topics: Semantic Logging Application Block
Nov 5, 2013 at 11:10 AM
My application writes log to flat file.
Whenever I launch my application, it overwrites the log file. It creates new log file each time.
But I want to write to existing log file, if log file exists already.
So, each time I launch my application, is it possible to write to existing log file?

Thanks in advance.
Nov 5, 2013 at 11:51 AM
It shouldn't overwrite existing files; files are opened using FileMode.Append. Can you post the code you are using?


Randy Levy
Enterprise Library support engineer
Support How-to
Nov 5, 2013 at 12:08 PM
I am using the code below :

ObservableEventListener listener = new ObservableEventListener();
listener.EnableEvents(Log.Logger, EventLevel.LogAlways, Log.Keywords.Trace);

Here are the steps :
1) I start my application which writes log.
2) The file is appened for each log, when my application runs.
3) I stop my application.
4) I restart my apllication.
5) The log file is overwritten. (A new log file is created).

Here in step 5, I want to write log to existing log file without overwriting it.
Is this possible?
Nov 6, 2013 at 12:05 PM
Besides the unrecognized escape sequence compile error ("C:\Debug.log" vs "C:\Debug.log") the code should be fine. When I run the code it works as expected. Are you sure the file is being overwritten? Maybe there is another error that's occurring and the file is not being written to? Try running EventSourceAnalyzer.InspectAll(Log.Logger); and see if there are any exceptions.

Randy Levy
Enterprise Library support engineer
Support How-to
Nov 7, 2013 at 2:24 PM
You are correct randylevy. In the enterprise library, the logs are appended in the existing file and not overwritten.
My file was being overwritten by my application that I haven't noticed.
Thanks for the reply.