Is logging an exception possible without file lock?

Topics: Exception Handling Application Block, Logging Application Block
Aug 28, 2008 at 11:52 AM
Edited Aug 28, 2008 at 11:53 AM

Using the ExceptionHandlingWithLogging Quickstart application, an exception written to a text file also locks the file until application closes. I cant delete it after the log has been written. For various reasons I would like that an Exception log does not lock the file.

However I cant seem to find any factory classes that would enable me to do this. I guess the problem is that the ExceptionHandling routines always uses a static LogWriter class. From what I can see theres no way to enable the Exception Logging to use a LogWriter created from a factory class (so I can dispose of that writer).

I can always change the entlib code but this is only when all other possibilities have been tried..Any ideas on how to do this?

Sep 5, 2008 at 7:58 AM
Hi Werner,

Im afraid u've to get into entlib code and write ur own formatter.
The FileStream logic is not implemented in the LogWriter class. Infact its in the TextWriterTraceListener class from which FlatFileTraceListener is eventually inherited. If u want to change the FileStream creation code you have to write ur own Listener which will incorporate the FileStream creation and closing code. Have a look at TallyKeepingFileStreamWriter class which closes the FileStream and reopens it when doing the rolling thing. I dont know why u want to do it, but in order to achieve what u want, u have to close and open the File Stream on every log entry which is not a best practice specially if ur logging alot of entries.