title: .Net Windows Service and Custom Trace Listeners
body: <p>I have all of my service logic encapsulated in class library.  When I instantiate the class library in a command line app I receive my trace information.</p>
  
  <p>When I instantiate the class in a Windows Service, I see that my Custom trace listener has created the logs directory and start a file, but it stays a 0 KB.</p>
  
  <p>Both applications have this in the .config:</p>
  
  <pre><code> &lt;system.diagnostics&gt;
  &lt;switches&gt;
    &lt;add name="PTraceSwitch" value="Verbose" /&gt;
  &lt;/switches&gt;
  &lt;trace autoflush="true"&gt;
    &lt;listeners&gt;
      &lt;add name="CustomXmlWriterTraceListener" /&gt;
      &lt;add name="MyServiceEventListener"  /&gt;
      &lt;remove name="Default" /&gt;
    &lt;/listeners&gt;
  &lt;/trace&gt;
  &lt;sharedListeners&gt;
    &lt;add
       type="CustomUtilities.CustomXmlWriterTraceListener, CustomUtilities"
       name="CustomXmlWriterTraceListener"
       initializeData="Logs\MyService.svclog"
       RollLogAtMidnight="True"
       DateFormat="yyyy.MM.dd"
       MaxFileSizeMB="1"
       CompressLogsOlderThanTimeSpan="1.00:0:00"
       DeleteLogsOlderThanTimeSpan="30.00:00:00"/&gt;
  
    &lt;add name="MyServiceEventListener"
         type="System.Diagnostics.EventLogTraceListener"
         initializeData="MyServiceEventLog"&gt;
      &lt;filter type="System.Diagnostics.EventTypeFilter"
        initializeData="Warning" /&gt;
    &lt;/add&gt;
  &lt;/sharedListeners&gt;
  </code></pre>
  
  <p></p>