I'm working on a console app that needs to provide integrated logging of its own output. Sure, you could do a standard console output redirect, but I wanted the app to be responsible for logging its own output. I decided to write my own
TraceListener that automatically creates IIS-style cyclic logfiles using the
Trace method, like so:
This is a companion discussion topic for the original blog entry at: http://www.codinghorror.com/blog/2005/03/logging-tracelistener.html
Well, if it has the word “Enterprise” in it, it’s already kind of suspect
I haven’t worked with it much. I hear it’s very heavy and extremely configuration intensive.
Great bit of code.
I was thinking of doing the same sort of thing using the Logging block in the Enterprise Library. I found a ‘rolling file sink’ here:
Are you a fan of the Enterprise Library stuff yourself?
Hi. Thats some nice formatting for the code especially with the print and view plane. Are you using some formatting tool readily available or are you formatting this yourself?
Very good!!! I had to put a synclock in the OpenLogFile. Could it be necessary in case of multi-threads applications?
_sw = File.AppendText(FileName)
_sw.AutoFlush = _AutoFlush
First off thanks for sharing this code.
I tried using it in VS2005 and the close method kept erroring out on the closing of the stream. Not sure how to resolve this
Your code has me very useful, only has a small error in the following piece of code: “(? <=” & Name & “=) d +” you forgot the “” before the “d +” would look like this: '(<= “& name &” =) \ d + "