Defining multiple TraceSources not running

后端 未结 1 1614
抹茶落季
抹茶落季 2021-01-26 00:37

I\'m new with TraceSource so I\'m doing some investigation into how it can/ can\'t be used (basically pros and cons).

Something I do like is that I can get dumps from wi

相关标签:
1条回答
  • 2021-01-26 00:54

    Found the problem, a complete noob mistake, both my TraceSource items have a Listener which is writing to the same file. Although I'm not sure exactly the error, but it'd be some kind of clash when writing.

    If you want to have multiple sources using the same listener you need to use the <sharedListeners /> like this:

    <system.diagnostics>
    <trace autoflush="true" />
    <sources>
      <source name="MyCustomTracer"
              switchValue="Information, ActivityTracing">
        <listeners>
           <add name="sdt" />
        </listeners>
      </source>
      <source name="System.Net"
              switchValue="Information, ActivityTracing, Critical">
        <listeners>
          <add name="sdt" />
        </listeners>
      </source>
    </sources>
    <sharedListeners>
        <add name="sdt"
            type="System.Diagnostics.XmlWriterTraceListener"
            initializeData= "traceOutput.log" />
    </sharedListeners>
    </system.diagnostics>
    
    0 讨论(0)
提交回复
热议问题