<sources>
<source name="TraceSourceApp" switchName="sourceSwitch" switchType="System.Diagnostics.SourceSwitch">
<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="All"/>
</switches>
<sharedListeners>
<add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="myListener.log">
<filter type="System.Diagnostics.EventTypeFilter" initializeData="Warning"/>
</add>
</sharedListeners>
//System.Diagnostics.TextWriterTraceListener is whatever inherit TraceListener
public static void Test1()
{
TraceSource mySource11 = new TraceSource("TraceSourceApp");
mySource11.TraceEvent(TraceEventType.Error, 1,
"Error message.");
mySource11.TraceEvent(TraceEventType.Warning, 2,
"Warning message."+DateTime.Now);
mySource11.Close();
}