title: How to invoke TraceListener.Write(object) through TraceSource
body: <p>We have a custom TraceListener implementation which only logs when a specific object (LogMessage) is received. This all works well when using directly with the <code>Trace.Write(object)</code> method.</p>
  
  <p>Due to Performance reason, I want to separate the Listener, so all non-relevant Trace messages are not passed to the listener. Therefore I created a specific TraceSource whith only this listener attached. </p>
  
  <p>Now I struggle to pass my custom log object (LogMessage) to the listener using the TraceSource. The <code>TraceSource.TraceData(TraceEventType, int, object)</code> always invokes the <code>TraceListener.Write(string)</code> method, not the <code>TraceListener.Write(object)</code> method.</p>
  
  <p>Is there any way I can pass the custom object to the Listener using the TraceSource?</p>
  
  <p>Sample code:  </p>
  
  <pre class="lang-cs prettyprint-override"><code>using System.Diagnostics;
  
  namespace Sample
  {
      public class LogMessage
      {
          public byte[] Data { get; set; }
          //...
      }
  
      public class Sample
      {
          public void Foo()
          {
              var ts = new TraceSource("Test");
  
              var lm = new LogMessage();
              //lm.Data = ...;
  
              //this works: calls the Write(object) method in listener
              Trace.Write(lm);
  
              //this doesn't work: calls the Write(string) method in listener
              ts.TraceData(TraceEventType.Information, 0, lm);
          }
      }
  
      public class MyListener : TraceListener
      {
          public override void Write(string message)
          {
              //not in use
          }
  
          public override void WriteLine(string message)
          {
              //not in use
          }
  
          public sealed override void Write(object o)
          {
              if (o is LogMessage)
              {
                  //do someting with the LogMessage
              }
          }
      }
  }
  </code></pre>
  
  <p>Thanks
  Thomas</p>