Trace.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / TrustUi / MS / Internal / documents / Application / Trace.cs / 1 / Trace.cs

                            //------------------------------------------------------------------------------ 
// 
//    Copyright (C) Microsoft Corporation.  All rights reserved. 
//
//  
// Utility class for Trace switches and methods for XpsViewer.
//  
// 
// History:
//  08/28/2005: [....]: Initial implementation. 
//-----------------------------------------------------------------------------

using System;
using System.Diagnostics; 
using System.Globalization;
using System.Security; 
 
namespace MS.Internal.Documents.Application
{ 
/// 
/// Utility class for Trace switches and methods for XpsViewer.
/// 
internal static class Trace 
{
    #region Internal Methods 
    //------------------------------------------------------------------------- 
    // Internal Methods
    //------------------------------------------------------------------------- 

    /// 
    /// Will permit only internet zone permissions for TraceListeners and is
    /// safe to use inside of asserts for partial trust code. 
    /// 
    ///  
    /// Critical: 
    ///  - Used in Assert blocks we must always revert to our lowest permission
    ///    set because registered TraceListners may usurpe our evilvations. 
    /// TreatAsSafe:
    ///  - Marked Critical for audit only that PermitOnly is performed as first
    ///    operation to ensure integrity of other reviews that depended on this
    ///    fact. 
    /// 
    [SecurityCritical, SecurityTreatAsSafe] 
    internal static void SafeWrite( 
        BooleanSwitch boolSwitch, string format, params object[] args)
    { 
        InternetPermissionSet.PermitOnly();

        if (AvTrace.IsWpfTracingEnabledInRegistry())
        { 
            System.Diagnostics.Trace.WriteLineIf(
                boolSwitch.Enabled, 
                string.Format( 
                CultureInfo.CurrentUICulture,
                format, 
                args),
                boolSwitch.DisplayName);
        }
 
        CodeAccessPermission.RevertPermitOnly();
    } 
 
    /// 
    /// Will permit only internet zone permissions for TraceListeners and is 
    /// safe to use inside of asserts for partial trust code.
    /// 
    /// 
    /// Critical: 
    ///  - Used in Assert blocks we must always revert to our lowest permission
    ///    set because registered TraceListeners may usurp our permissions. 
    /// TreatAsSafe: 
    ///  - Marked Critical for audit only that PermitOnly is performed as first
    ///    operation to ensure integrity of other reviews that depended on this 
    ///    fact.
    /// 
    [SecurityCritical, SecurityTreatAsSafe]
    internal static void SafeWriteIf( 
        bool condition,
        BooleanSwitch boolSwitch, 
        string format, 
        params object[] args)
    { 
        InternetPermissionSet.PermitOnly();

        if (AvTrace.IsWpfTracingEnabledInRegistry())
        { 
            System.Diagnostics.Trace.WriteLineIf(
                boolSwitch.Enabled && condition, 
                string.Format( 
                CultureInfo.CurrentCulture,
                format, 
                args),
                boolSwitch.DisplayName);
        }
 
        CodeAccessPermission.RevertPermitOnly();
    } 
 
    #endregion Internal Methods
 
    #region Internal Fields
    //--------------------------------------------------------------------------
    // Internal Fields
    //------------------------------------------------------------------------- 

    internal static BooleanSwitch File = new BooleanSwitch( 
        FileSwitchName, FileSwitchName, "1"); 
    internal static BooleanSwitch Packaging = new BooleanSwitch(
        PackagingSwitchName, PackagingSwitchName, "1"); 
    internal static BooleanSwitch Presentation = new BooleanSwitch(
        PresentationSwitchName, PresentationSwitchName, "1");
    internal static BooleanSwitch Rights = new BooleanSwitch(
        RightsSwitchName, RightsSwitchName, "1"); 
    internal static BooleanSwitch Signatures = new BooleanSwitch(
        SignaturesSwitchName, SignaturesSwitchName, "1"); 
    #endregion Internal Fields 

    #region Private Fields 
    //--------------------------------------------------------------------------
    // Private Fields
    //--------------------------------------------------------------------------
 
    /// 
    /// Critical: 
    ///  - Used in Assert blocks we must always revert to our lowest permission 
    ///    set because registered TraceListeners may usurp our permissions.
    /// TreatAsSafe: 
    ///  - Marked Critical for audit only that PermitOnly is performed as first
    ///    operation to ensure integrity of other reviews that depended on this
    ///    fact.
    ///  
    [SecurityCritical, SecurityTreatAsSafe]
    private static readonly NamedPermissionSet InternetPermissionSet = 
        new NamedPermissionSet("Internet"); 

    private const string FileSwitchName = "XpsViewerFile"; 
    private const string PackagingSwitchName = "XpsViewerPackaging";
    private const string PresentationSwitchName = "XpsViewerUI";
    private const string RightsSwitchName = "XpsViewerRights";
    private const string SignaturesSwitchName = "XpsViewerSignatures"; 
    #endregion Private Fields
} 
} 

// 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