Create TraceSource and SourceSwitch: switch level : TraceSource « Development « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;


public class MainClass
{
    public static void Main()
    {
        TraceSource ts = new TraceSource("MyTraceSource");
        ts.Listeners.Add(new ConsoleTraceListener());
        ts.Switch = new SourceSwitch("mySource");
        ts.Switch.Level = SourceLevels.Error;

        ts.TraceEvent(TraceEventType.Information, 0, "Information event");
        ts.TraceEvent(TraceEventType.Error, 0, "Error event");
    }
}








14.29.TraceSource
14.29.1.Create TraceSource and trace events
14.29.2.Create TraceSource and Trace Information
14.29.3.Create TraceSource and SourceSwitch: switch level