Specify custom TraceListener in App.config

  • Thread starter Thread starter Rick
  • Start date Start date
R

Rick

Greetings.

I have overridden the WriteLine method of the TextWriterTraceListener
in my own derived class:

namespace IOIShared {

public class TextWriterTraceListenerWithTime :
System.Diagnostics.TextWriterTraceListener {

public override void WriteLine(string message) {
base.Write(DateTime.Now.ToString());
base.Write(" ");
base.WriteLine(message);
}
}

That compiles just fine. To go along with this, I use this App.config
file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<switches>
<add name="DataMessagesSwitch" value="0" />
<add name="TraceLevelSwitch" value="1" />
</switches>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="fileLogger"
type="IOIShared.TextWriterTraceListenerWithTime"
initializeData="C:\IOICliser_2\LogFile.log" />
<remove name="Default" />
</listeners>
</trace>
</system.diagnostics>
</configuration>

Sadly, when the program runs, I get the message:

An unhandled exception of type
'System.Configuration.ConfigurationErrorsException' occurred in
System.dll .
Additional information: Couldn't find type for class
IOIShared.TextWriterTraceListenerWithTime.

When I replace the "type=" line with:

type="System.Diagnostics.TextWriterTraceListener"

.. . . it works fine, except of course I don't get a timestamp on my
lines.

Can you tell me what I'm doing wrong?

Regards, Rick
 
Back
Top