Hi. I want to implement a custom trace listener like follows:
public class TraceListener : System.Diagnostics.TraceListener
{
public override void Write(string message)
{
LogToDatabase(message);
}
public override void WriteLine(string message)
{
LogToDatabase(message);
}
}
Now suppose an error occurs somewhere in the code. In catch block I want to do
Trace.TraceError(ex.ToString())
where ex is caught exception. Now the problem is that in my MyTraceListener the message parameters of Write method and WriteLine method are different. And even more interesting the string generated by ex.ToString() is passed as parameter in WriteLine method but not in Write.