views:

361

answers:

3

I have the following scenario: 1. .NET UI side uses Logging App Block to write to a flat file 2. Unmanaged Windows Service uses a proprietary logger to write to the same file as 1.

Question: Is there a way to enable FlatFile TraceListener to close it's file handle once the entry is logged so that the Windows Service could also write to the file?

Thanks!

Update: I included Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Writer.Dispose(); and this closes the stream, so this would do the trick -- just curious if there is another way to do this.

Update2: Final Notes

P&P proposes to write to a single MSMQ from multiple applications. This way you won't need to call Dispose(), etc.

A: 

I think that your choice is the best way to take care of it - just dispose the writer after you're done, which should finalize and release all of the resources that the writer still holds.

Also, I'd be worried about both processing trying to write at the same time and it causing an exception, but perhaps the App Block has some workaround code for that built in.

rwmnau
+1  A: 

I've had to deal with this using log4net. I wasn't able to make use of the logging framework's file logging support at all, and had to roll my own log appender that catches sharing violations. At that point, your choices are either to buffer events in memory and write them out later or to block until you can get access to the file.

Jeffrey Hantin
A: 

Where do you get the .Dispose from? I type in EnterpriseLibrary.Logging.Logger.Writer but the .Writer as no methods or properties, no .Dispose.

Thanks,

TCW

Found it :

Import Microsoft.Practices.EntLib.Common does the trick.

TCW