Tracer Class Extension?

Topics: Logging Application Block
Aug 15, 2008 at 8:47 AM
Edited Aug 15, 2008 at 8:47 AM

I have created a wrapper around the logger class for our project which exposes less .Write methods with enums for categories,events etc to ensure that the logging is consistent. It also logs extra information in the LogEntry class because i have extended the class and added properties which insert extended properties. Anyways, the logging part works well as in my custom database trace listener i am using these properties to log the extra information in our database table.

The problem is that for performance tracing i need to log extra information. But the "Tracer" class simply writes a string message. How can i extend the tracer class to log a custom LogEntry object such that it records start time and end time, time elapsed separatly and not as part of the string message.

The only thing i can think of is, to copy all of the code in Tracer class and just change the appropriate methods :(  (Can we use extension methods to somehow override the private methods?)

Aug 15, 2008 at 11:56 AM

You will need to create your own copy of the Tracer class. Extension methods will not do it; they are really syntactic sugaring that looks like invoking a method on an object but really invoke a static method in a different class while the original class remains unchanged.

Aug 15, 2008 at 2:07 PM
Thanks, i thought that would be the case. I didnt want to do this because i dont want to touch the Enterprise Library code. So far all the work i have done is simply wrapper classes around the logger class and LogEntry class.

i now plan to copy the tracer class into a separate file and change the class to partial. Then i will remove the methods that need from Copied tracer class and implement them in the 2nd partial class. This way, it will be easy to remember what code was changed and in future it will make it easier to keep up with the updates to the core Tracer class.

Thanks again.