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 NotInheritable Class TraceSection
	Inherits ConfigurationSection
Dim instance As TraceSection

public final class TraceSection extends ConfigurationSection
public final class TraceSection extends ConfigurationSection
Not applicable.

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.


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.

Imports System
Imports System.Collections
Imports System.Collections.Specialized
Imports System.IO
Imports System.Text
Imports System.Text.RegularExpressions
Imports System.Configuration
Imports System.Web.Configuration

Namespace Samples.Aspnet.SystemWebConfiguration
    ' Accesses the System.Web.Configuration.TraceSection members
    ' selected by the user.
    Class UsingTraceSection
        Public Shared Sub Main()
            ' Process the System.Web.Configuration.TraceSectionobject.
                ' Get the Web application configuration.
                Dim configuration As System.Configuration.Configuration = _

                ' Get the section.
                Dim traceSection As System.Web.Configuration.TraceSection = _
                    CType(configuration.GetSection("system.web/trace"), _

                ' Get the current PageOutput property value.
                Dim pageOutputValue As Boolean = traceSection.PageOutput

                ' Set the PageOutput property to true.
                traceSection.PageOutput = True

                ' Get the current WriteToDiagnosticsTrace property value.
                Dim writeToDiagnosticsTraceValue As Boolean = traceSection.WriteToDiagnosticsTrace

                ' Set the WriteToDiagnosticsTrace property to true.
                traceSection.WriteToDiagnosticsTrace = True

                ' Get the current MostRecent property value.
                Dim mostRecentValue As Boolean = traceSection.MostRecent

                ' Set the MostRecent property to true.
                traceSection.MostRecent = True

                ' Get the current RequestLimit property value.
                Dim requestLimitValue As Int32 = traceSection.RequestLimit

                ' Set the RequestLimit property to 256.
                traceSection.RequestLimit = 256

                ' Get the current LocalOnly property value.
                Dim localOnlyValue As Boolean = traceSection.LocalOnly

                ' Set the LocalOnly property to false.
                traceSection.LocalOnly = False

                ' Get the current Enabled property value.
                Dim enabledValue As Boolean = traceSection.Enabled

                ' Set the Enabled property to false.
                traceSection.Enabled = False

                ' Get the current Mode property value.
                'Dim modeValue As TraceDisplayMode = traceSection.TraceMode

                ' Set the Mode property to TraceDisplayMode.SortByTime.
                'traceSection.Mode = TraceDisplayMode.SortByTime

                ' Update if not locked.
                If Not traceSection.SectionInformation.IsLocked Then
                    Console.WriteLine("** Configuration updated.")
                    Console.WriteLine("** Could not update, section is locked.")
                End If
            Catch e As System.ArgumentException
                ' Unknown error.
                Console.WriteLine( _
                    "A invalid argument exception detected in UsingTraceSection Main. Check your")
                Console.WriteLine("command line for errors.")
            End Try
        End Sub
    End Class ' UsingTraceSection.
End Namespace ' Samples.Aspnet.SystemWebConfiguration

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions