<configuration>
<system.diagnostics>
<sources>
<source name="TraceSourceApp" switchName="sourceSwitch" switchType="System.Diagnostics.SourceSwitch"> //switchValue="Warning" 也可以在此处直接指定switch的值
<listeners>
<add name="console" type="System.Diagnostics.ConsoleTraceListener">
<filter type="System.Diagnostics.EventTypeFilter" initializeData="Warning"/>
</add>
<add name="myListener"/>
<remove name="Default"/>
</listeners>
</source>
</sources>
<switches>
<add name="sourceSwitch" value="Warning"/>
</switches>
<sharedListeners>
<add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="myListener.log">
<filter type="System.Diagnostics.EventTypeFilter" initializeData="Error"/>
</add>
</sharedListeners> <trace autoflush="true" indentsize="4">
<listeners>
<add name="myListener" />
</listeners>
</trace>
</system.diagnostics>
</configuration>