Csharp/C Sharp by API/System.Diagnostics/TraceSource

Материал из .Net Framework эксперт
Версия от 12:13, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

new TraceSource

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

public class MainClass
{
    public static void Main()
    {
        Trace.Listeners.Add(new ConsoleTraceListener());
        TraceSource customerTraceSource = new TraceSource("YourClassName");
        Trace.WriteLine("Instantiated a new customer {0}", "asdf");
        Debug.Assert(1 == 2, "1 ==2");
        customerTraceSource.TraceEvent(TraceEventType.Warning, 1000,"data might be corrupt");
    }
}


TraceSource.Listeners.Add

  

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");
    }
}


TraceSource.Switch

  

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");
    }
}


TraceSource.TraceEvent

  

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");
    }
}


TraceSource.TraceInformation

  

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

public class MainClass
{
    public static void Main()
    {
        TraceSource myTraceSource = new TraceSource("myTraceSource");
        myTraceSource.TraceInformation("Customer successfully loaded from DB");
        myTraceSource.Flush();
        
        
    }
}