Menu

Debug Logs- a C# approach

April 3, 2015 - .NET, C#, Programming

Somehow I’ve managed to never write about my Debug log class, looking through my post history.

It’s a versatile Debug Logging class that effectively hooks into and allows tracing of Trace.Write and Debug.Write method call output. I use it to redirect all Debug.Print() output to a text file for later examination. Some of my original considerations included being easy to use and add to existing software programs, as well as being able to do it’s job with as little interaction as possible. I’ve been able to use this successfully in it’s original program (BASeBlock) as well as inserting and using the class for Debug log functionality in software created and maintained as part of my Job, and it has worked wonderfully.

Example usage is straightforward- you enable logging by simply accessing the “EnableLogging” property; typically I set it to true for obvious reasons. The Static initializer of the class sets everything up from there:

And BAM! We’ve got a fully functional debug log- after the debug logs become a week old, they get purged, too! How is that for convenience?

Have something to say about this post? Comment!

Tags: ,