Specify custom TraceListener in App.config

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
 

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