Shared Listener as the name suggests can be used by 2 or more trace sources(eg. Say one logs Messages and other logs Errors, Warnings etc) by using a friendly name. But if both of them plan to use the same tracefile,

Then the advantage here is you don’t have to repeat the Type, culture etc for the filename . See the highlighted portion below, this could be shared by different trace sources

 

These are the differences between the Listener and Shared Listener as per MSDN (http://msdn.microsoft.com/en-us/library/ms229501.aspx)

 

<sharedListeners> Contains listeners that any source or trace element can reference.

·         These listeners do not receive any traces by default

·         It is not possible to retrieve these listeners at run time.

·         Listeners identified as shared listeners can be added to sources or traces by name.

·         Adding a listener to the shared listeners collection does not make it an active listener. It must still be added to a trace source or a trace by adding it to the Listeners collection for that trace element

 

 

 Sample with SharedListeners

 

  <system.diagnostics>

    <sources>

      <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">

        <listeners>

          <add type="System.Diagnostics.DefaultTraceListener" name="Default">

            <filter type="" />

          </add>

          <add name="ServiceModelMessageLoggingListener">

            <filter type="" />

          </add>

        </listeners>

      </source>

    </sources>

    <sharedListeners>

      <add initializeData="d:\web_messages.svclog"

        type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

        name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">

        <filter type="" />

      </add>

    </sharedListeners>

    <trace autoflush="true" />

  </system.diagnostics>

 

 Sample without SharedListeners

 

<system.diagnostics>

            <trace useGlobalLock="false" />

            <sources>

   <source name="System.ServiceModel" switchValue="Information, ActivityTracing"

    >

  <listeners>

    

     <add initializeData="POCTraces.svclog" type="System.Diagnostics.XmlWriterTraceListener"

      name="ourtraceListener" traceOutputOptions="LogicalOperationStack">

    

     </add>

    </listeners>

   </source>

  </sources>

</system.diagnostics>