UPDATE - no need to answer this now, I decided below.
Hi, I am trying to implement my own trace listener in .NET, but with the problem of adding a trace listener through the configuration file.
I found a similar entry in the stack overflow, but it doesn't seem to help ( How to define a custom TraceListener in app.config ).
Exception Message:
ErrExException - "Failed to create ApplicationFramework.TraceListeners.TextLogTraceListener, ApplicationFramework.TraceListeners, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null."
As you can see in my code below, I even used the name AssemblyQualified after trying without it.
Configuration and dll exist in the application that references the listener.
Can anyone determine what I can do wrong here?
C # code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace ApplicationFramework.TraceListeners { public class TextLogTraceListener : System.Diagnostics.TextWriterTraceListener { public override void Write( string message ) { using (FileStream fs = new FileStream( "C:\\Test\\trace.log", FileMode.Append )) { StreamWriter sw = new StreamWriter( fs ); sw.Write( message ); } } public override void WriteLine( string message ) { using (FileStream fs = new FileStream( "C:\\Test\\trace.log", FileMode.Append )) { StreamWriter sw = new StreamWriter( fs ); sw.Write( message ); } } } }
Config:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.diagnostics> <trace autoflush="true" indentsize="4"> <listeners> <add name="TextListener" type="ApplicationFramework.TraceListeners.TextLogTraceListener, ApplicationFramework.TraceListeners, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" initializeData="trace.log" /> <remove name="Default" /> </listeners> </trace> </system.diagnostics> </configuration>
A simple trace call in the application for links:
Trace.WriteLine( "Test" );