Extend .NET Class, or Write a New Class

J

Jeremy S.

I'm implementing logging via the TraceSource class and related TraceSwitch
and TraceListeners classes.

The TextWriterTraceListener does much of what I need. But it does not roll
the log over at some max size, and is missing a couple of other feaures.

It appears that I have two options for getting the behavior I want:
1. Extend the TextWriterTraceListener (it isn't sealed), adding the features
I want in my derived class.
2. Write my own custom trace listener, extending the base TraceListener
class. I would then proceed to duplicate basically all of the functionality
in the TextWriterTraceListener and add the new functionality I want.

My tendency is to go with #1 above and extend the existing
TextWriterTraceListener class.

Are there any good reasons to NOT do that? Would it be better for me to
write a new class instead? (and yes, I'm aware of log4net, but don't want to
go that route for now).

I appreciate your thoughts on this.
 
F

Frans Bouma [C# MVP]

Jeremy said:
I'm implementing logging via the TraceSource class and related
TraceSwitch and TraceListeners classes.

The TextWriterTraceListener does much of what I need. But it does not
roll the log over at some max size, and is missing a couple of other
feaures.

It appears that I have two options for getting the behavior I want:
1. Extend the TextWriterTraceListener (it isn't sealed), adding the
features I want in my derived class. 2. Write my own custom trace
listener, extending the base TraceListener class. I would then
proceed to duplicate basically all of the functionality in the
TextWriterTraceListener and add the new functionality I want.

3. use Log3Net and spend the time you save with that on nice things in
life :)

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top