How to configure message filtering through switches
Here is my code
public static TraceSource TS = new TraceSource("myTraceSrc", SourceLevels.All);
static void Main(string[] args)
{
TS.TraceInformation("Hello Information Trace from Main");
TS.TraceEvent(System.Diagnostics.TraceEventType.Error, 1, "Hello Error Trace from Main");
}
here is config file
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="myTraceSrc" switchName="switch1" >
<listeners>
<add type="System.Diagnostics.TextWriterTraceListener" name="myLocalListener" initializeData="c:\WasteBin\Test.Log" />
<add name="consoleListener" />
</listeners>
</source>
</sources>
<sharedListeners>开发者_运维知识库
<add type="System.Diagnostics.ConsoleTraceListener" name="consoleListener" traceOutputOptions="None" />
<add type="System.Diagnostics.EventTypeFilter" name="EventListener" traceOutputOptions="None" />
</sharedListeners>
<switches>
<add name="switch1" value="all" />
</switches>
</system.diagnostics>
I want all my messages to go to console and text file but only error should go to events log. How can I set it up using configuration settings?
Try to use logging libraries (Nlog, log4net) for your tasks. They have message filtering and routing.
精彩评论