Csharp/C Sharp by API/System.Diagnostics/TraceSource — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 12:13, 26 мая 2010

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