title: .Net Custom Trace file name
body: <p>I would like my application to write out different trace files named like MachineName_UserName_yyyymmdd_hhmmss.txt where the username is the currently logged in user and the time is the start time of the application. The .Net listener TextWriterTraceListener only seems to support a hard coded file name specified in the config file. Is there a way to do this without writing a custom trace listener.</p>
  
  <p>Assuming I have to write a custom trace listener, I have implemented a tracelistener like this:</p>
  
  <pre><code>Imports System.Diagnostics
  
  Public Class MyCustomTraceListener
      Inherits TextWriterTraceListener
  
      Public Sub New()
          'Need to do it this way as the Base constructor call has to be the first statement
          MyBase.New(String.Format("AppNameTraceFile_{0}_{1}_{2}{3}{4}-{5}{6}{7}.txt", _
                                                         Environment.MachineName, _
                                                         Environment.UserName, _
                                                         DateTime.Now.ToString("yyyy"), _
                                                         DateTime.Now.ToString("MM"), _
                                                         DateTime.Now.ToString("dd"), _
                                                         DateTime.Now.ToString("HH"), _
                                                         DateTime.Now.ToString("mm"), _
                                                         DateTime.Now.ToString("ss")))
          Me.IndentSize = 4
      End Sub
  
  End Class
  </code></pre>
  
  <p>In the config file, I have configured the trace source like this:</p>
  
  <pre><code>  &lt;system.diagnostics&gt;
      &lt;trace autoflush="true"/&gt;
      &lt;sources&gt;
        &lt;source name="MyTraceSource"
                switchName="mySwitch"
                switchType="System.Diagnostics.SourceSwitch" &gt;
          &lt;listeners&gt;
            &lt;clear/&gt;
            &lt;add name="MyTraceListener"
              type="MyNameSpace.MyCustomTraceListener"
              traceOutputOptions="ProcessId, DateTime, Callstack" /&gt;
          &lt;/listeners&gt;
        &lt;/source&gt;
      &lt;/sources&gt;
      &lt;switches&gt;
        &lt;add name="mySwitch" value="Warning" /&gt;
      &lt;/switches&gt;
    &lt;/system.diagnostics&gt;
  </code></pre>
  
  <p>I am creating the trace source like so:</p>
  
  <pre><code>Dim tsTraceSource As TraceSource = New TraceSource("MyTraceSource")
  tsTraceSource.TraceEvent(TraceEventType.Warning, 0, "warning message")
  </code></pre>
  
  <p>However, at startup, I keep getting an error that the type "MyNameSpace.MycustomTraceListener" could not be found.</p>
  
  <p>Does anyone see what the problem is here ?</p>
  
  <p>Thanks.</p>