Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

TraceSection Class

Configures the ASP.NET trace service. This class cannot be inherited.

Namespace:  System.Web.Configuration
Assembly:  System.Web (in System.Web.dll)
public sealed class TraceSection : ConfigurationSection

The TraceSection type exposes the following members.

  NameDescription
Public methodTraceSectionInfrastructure. Initializes a new instance of the TraceSection class using default settings.
Top
  NameDescription
Public propertyCurrentConfigurationGets a reference to the top-level Configuration instance that represents the configuration hierarchy that the current ConfigurationElement instance belongs to. (Inherited from ConfigurationElement.)
Public propertyElementInformationGets an ElementInformation object that contains the non-customizable information and functionality of the ConfigurationElement object. (Inherited from ConfigurationElement.)
Protected propertyElementPropertyGets the ConfigurationElementProperty object that represents the ConfigurationElement object itself. (Inherited from ConfigurationElement.)
Public propertyEnabledGets or sets a value indicating whether the ASP.NET trace service is enabled.
Protected propertyItem[ConfigurationProperty]Gets or sets a property or attribute of this configuration element. (Inherited from ConfigurationElement.)
Protected propertyItem[String]Gets or sets a property, attribute, or child element of this configuration element. (Inherited from ConfigurationElement.)
Public propertyLocalOnlyGets or sets a value indicating whether the ASP.NET trace viewer (Trace.axd) is available only to requests from the host Web server.
Public propertyLockAllAttributesExceptGets the collection of locked attributes. (Inherited from ConfigurationElement.)
Public propertyLockAllElementsExceptGets the collection of locked elements. (Inherited from ConfigurationElement.)
Public propertyLockAttributesGets the collection of locked attributes (Inherited from ConfigurationElement.)
Public propertyLockElementsGets the collection of locked elements. (Inherited from ConfigurationElement.)
Public propertyLockItemGets or sets a value indicating whether the element is locked. (Inherited from ConfigurationElement.)
Public propertyMostRecentGets or sets a value indicating whether the most recent requests are always stored on the server.
Public propertyPageOutputGets or sets a value indicating whether the ASP.NET trace information is appended to the output of each page.
Protected propertyPropertiesGets the collection of properties. (Inherited from ConfigurationElement.)
Public propertyRequestLimitGets or sets a value indicating the maximum number of requests to the application for which ASP.NET stores trace information.
Public propertySectionInformationGets a SectionInformation object that contains the non-customizable information and functionality of the ConfigurationSection object. (Inherited from ConfigurationSection.)
Public propertyTraceModeGets or sets the order in which ASP.NET trace information is displayed.
Public propertyWriteToDiagnosticsTraceGets or sets a value indicating whether the messages emitted through the page trace are forwarded to an instance of the Trace class.
Top
  NameDescription
Protected methodDeserializeElementReads XML from the configuration file. (Inherited from ConfigurationElement.)
Protected methodDeserializeSectionInfrastructure. Reads XML from the configuration file. (Inherited from ConfigurationSection.)
Public methodEqualsCompares the current ConfigurationElement instance to the specified object. (Inherited from ConfigurationElement.)
Public methodGetHashCodeGets a unique value representing the current ConfigurationElement instance. (Inherited from ConfigurationElement.)
Protected methodGetRuntimeObjectReturns a custom object when overridden in a derived class. (Inherited from ConfigurationSection.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodInitSets the ConfigurationElement object to its initial state. (Inherited from ConfigurationElement.)
Protected methodInitializeDefaultUsed to initialize a default set of values for the ConfigurationElement object. (Inherited from ConfigurationElement.)
Protected methodIsModifiedIndicates whether this configuration element has been modified since it was last saved or loaded when implemented in a derived class. (Inherited from ConfigurationSection.)
Public methodIsReadOnlyGets a value indicating whether the ConfigurationElement object is read-only. (Inherited from ConfigurationElement.)
Protected methodResetResets the internal state of the ConfigurationElement object, including the locks and the properties collections. (Inherited from ConfigurationElement.)
Protected methodResetModifiedResets the value of the IsModified method to false when implemented in a derived class. (Inherited from ConfigurationSection.)
Protected methodSerializeElementWrites the contents of this configuration element to the configuration file when implemented in a derived class. (Inherited from ConfigurationElement.)
Protected methodSerializeSectionInfrastructure. Creates an XML string containing an unmerged view of the ConfigurationSection object as a single section to write to a file. (Inherited from ConfigurationSection.)
Protected methodSerializeToXmlElementWrites the outer tags of this configuration element to the configuration file when implemented in a derived class. (Inherited from ConfigurationElement.)
Protected methodSetReadOnlySets the IsReadOnly property for the ConfigurationElement object and all subelements. (Inherited from ConfigurationElement.)
Protected methodShouldSerializeElementInTargetVersionIndicates whether the specified element should be serialized when the configuration object hierarchy is serialized for the specified target version of the .NET Framework. (Inherited from ConfigurationSection.)
Protected methodShouldSerializePropertyInTargetVersionIndicates whether the specified property should be serialized when the configuration object hierarchy is serialized for the specified target version of the .NET Framework. (Inherited from ConfigurationSection.)
Protected methodShouldSerializeSectionInTargetVersionIndicates whether the current ConfigurationSection instance should be serialized when the configuration object hierarchy is serialized for the specified target version of the .NET Framework. (Inherited from ConfigurationSection.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Protected methodUnmergeModifies the ConfigurationElement object to remove all values that should not be saved. (Inherited from ConfigurationElement.)
Top

The TraceSection class provides a way to programmatically access and modify the content of the configuration file trace section. The trace section configures the ASP.NET trace functionality and controls how trace results are gathered, stored, and displayed.

When tracing is enabled, each page request generates trace messages that can be appended to the page output or stored in an application trace log. You can use the ASP.NET trace viewer (Trace.axd) to view the contents of the trace log.

NoteNote

The trace element is allowed in the system.web section of the configuration hierarchy in the Machine.config file and the Web.config files. It is not allowed in configuration files of Web subdirectories.

The following code example shows how to use the TraceSection type.

using System;
using System.Collections;
using System.Collections.Specialized;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Configuration;
using System.Web.Configuration;

namespace Samples.Aspnet.SystemWebConfiguration
{
    // Accesses the System.Web.Configuration.TraceSection members 
    // selected by the user. 
    class UsingTraceSection
    {
        public static void Main()
        {
            // Process the System.Web.Configuration.TraceSectionobject. 
            try
            {
                // Get the Web application configuration.
                System.Configuration.Configuration configuration = 
                    System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/aspnet");

                // Get the section.
                System.Web.Configuration.TraceSection traceSection = 
                    (System.Web.Configuration.TraceSection) 
                    configuration.GetSection("system.web/trace");

// Get the current PageOutput property value.
Boolean pageOutputValue = traceSection.PageOutput;

// Set the PageOutput property to true.
traceSection.PageOutput = true;



// Get the current WriteToDiagnosticsTrace property value.
Boolean writeToDiagnosticsTraceValue = traceSection.WriteToDiagnosticsTrace;

// Set the WriteToDiagnosticsTrace property to true.
traceSection.WriteToDiagnosticsTrace = true;



// Get the current MostRecent property value.
Boolean mostRecentValue = traceSection.MostRecent;

// Set the MostRecent property to true.
traceSection.MostRecent = true;



// Get the current RequestLimit property value.
Int32 requestLimitValue = traceSection.RequestLimit;

// Set the RequestLimit property to 256.
traceSection.RequestLimit = 256;



// Get the current LocalOnly property value.
Boolean localOnlyValue = traceSection.LocalOnly;

// Set the LocalOnly property to false.
traceSection.LocalOnly = false;



// Get the current Enabled property value.
Boolean enabledValue = traceSection.Enabled;

// Set the Enabled property to false.
traceSection.Enabled = false;



// Get the current Mode property value. 
// TraceDisplayMode modeValue = traceSection.TraceMode; 

// Set the Mode property to TraceDisplayMode.SortyByTime. 
// traceSection.Mode = TraceDisplayMode.SortByTime; 


                // Update if not locked. 
                if (! traceSection.SectionInformation.IsLocked)
                {
                    configuration.Save();
                    Console.WriteLine("** Configuration updated.");
                }
                else
                    Console.WriteLine("** Could not update, section is locked.");
            }
            catch (System.ArgumentException e)
            {
                // Unknown error.
                Console.WriteLine(
                    "A invalid argument exception detected in UsingTraceSection Main. Check your");
                Console.WriteLine("command line for errors.");
            }
        }
    } // UsingTraceSection class end.

} // Samples.Aspnet.SystemWebConfiguration namespace end.

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft. All rights reserved.