Defining multiple TraceSources not running

烂漫一生 提交于 2019-12-02 10:38:39

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>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!