DebugTrace.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / TransactionBridge / Microsoft / Transactions / Wsat / Messaging / DebugTrace.cs / 1 / DebugTrace.cs

                            //------------------------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------------------------

// Define tracing helpers for WS-AT 
using System;
using System.Diagnostics; 
 
namespace Microsoft.Transactions.Wsat.Messaging
{ 
    static class DebugTrace
    {
        static DebugTraceHelper instance = new DebugTraceHelper(
            "WSAT", 
            new TraceSwitch ("Microsoft.Transactions.Wsat",
                             "Tracing for WS-AT protocol")); 
 
        static bool tracePiiEnabled = false;
 
        //
        // Flags
        //
 
        public static bool Verbose
        { 
            get { return instance.TraceEnabled (TraceLevel.Verbose); } 
        }
 
        public static bool Info
        {
            get { return instance.TraceEnabled (TraceLevel.Info); }
        } 

        public static bool Warning 
        { 
            get { return instance.TraceEnabled (TraceLevel.Warning); }
        } 

        public static bool Error
        {
            get { return instance.TraceEnabled (TraceLevel.Error); } 
        }
 
        public static bool Pii 
        {
            get { return tracePiiEnabled; } 
            set
            {
                if (value)
                    Trace(TraceLevel.Warning, "PII tracing is enabled"); 

                tracePiiEnabled = value; 
            } 
        }
 
        //
        // Trace
        //
 
        public static void Trace(TraceLevel level, string text)
        { 
            instance.Trace(level, text); 
        }
 
        public static void Trace(TraceLevel level, string text, object arg0)
        {
            instance.Trace(level, text, arg0);
        } 

        public static void Trace(TraceLevel level, string text, object arg0, object arg1) 
        { 
            instance.Trace(level, text, arg0, arg1);
        } 

        public static void Trace(TraceLevel level, string text, object arg0, object arg1, object arg2)
        {
            instance.Trace(level, text, arg0, arg1, arg2); 
        }
 
        public static void Trace(TraceLevel level, string text, object arg0, object arg1, object arg2, object arg3) 
        {
            instance.Trace(level, text, arg0, arg1, arg2, arg3); 
        }

        //
        // PII 
        //
 
        public static void TracePii(TraceLevel level, string text) 
        {
            if (tracePiiEnabled) 
            {
                instance.Trace(level, text);
            }
        } 

        public static void TracePii(TraceLevel level, string text, object arg0) 
        { 
            if (tracePiiEnabled)
            { 
                instance.Trace(level, text, arg0);
            }
        }
 
        //
        // High level 
        // 

        public static void TraceEnter(string function) 
        {
            if (instance.TraceEnabled(TraceLevel.Verbose))
            {
                instance.Trace(TraceLevel.Verbose, "Enter {0}", function); 
            }
        } 
 
        public static void TraceLeave(string function)
        { 
            if (instance.TraceEnabled(TraceLevel.Verbose))
            {
                instance.Trace(TraceLevel.Verbose, "Leave {0}", function);
            } 
        }
 
        public static void TraceEnter(object obj, string function) 
        {
            if (instance.TraceEnabled(TraceLevel.Verbose)) 
            {
                instance.Trace(TraceLevel.Verbose, "Enter {0}.{1}", obj.GetType().Name, function);
            }
        } 

        public static void TraceLeave (object obj, string function) 
        { 
            if (instance.TraceEnabled (TraceLevel.Verbose))
            { 
                instance.Trace(TraceLevel.Verbose, "Leave {0}.{1}", obj.GetType().Name, function);
            }
        }
 
        public static void TraceSendFailure(Exception e)
        { 
            if (instance.TraceEnabled (TraceLevel.Warning)) 
            {
                Trace(TraceLevel.Warning, "Failure sending message: {0}", e.Message); 
            }
        }

        public static void TraceSendFailure(Guid enlistmentId, Exception e) 
        {
            if (instance.TraceEnabled (TraceLevel.Warning)) 
            { 
                TxTrace(TraceLevel.Warning, enlistmentId, "Failure sending message: {0}", e.Message);
            } 
        }

        //
        // enlistmentId present 
        //
 
        static string FormatEnlistmentTrace(Guid enlistmentId, string text) 
        {
            return enlistmentId.ToString() + " " + text; 
        }

        public static void TxTrace(TraceLevel level, Guid enlistmentId, string text)
        { 
            instance.Trace(level, FormatEnlistmentTrace(enlistmentId, text));
        } 
 
        public static void TxTrace(TraceLevel level, Guid enlistmentId, string text, object arg0)
        { 
            instance.Trace(level, FormatEnlistmentTrace(enlistmentId, text), arg0);
        }

        public static void TxTrace(TraceLevel level, Guid enlistmentId, string text, object arg0, object arg1) 
        {
            instance.Trace(level, FormatEnlistmentTrace(enlistmentId, text), arg0, arg1); 
        } 

        public static void TxTrace(TraceLevel level, Guid enlistmentId, string text, object arg0, object arg1, object arg2) 
        {
            instance.Trace(level, FormatEnlistmentTrace(enlistmentId, text), arg0, arg1, arg2);
        }
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK