TraceSection Klass
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Konfigurerar ASP.NET spårningstjänsten. Det går inte att ärva den här klassen.
public ref class TraceSection sealed : System::Configuration::ConfigurationSection
public sealed class TraceSection : System.Configuration.ConfigurationSection
type TraceSection = class
inherit ConfigurationSection
Public NotInheritable Class TraceSection
Inherits ConfigurationSection
- Arv
Exempel
I följande kodexempel visas hur du använder typen TraceSection .
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.
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.
Try
' Get the Web application configuration.
Dim configuration As System.Configuration.Configuration = _
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/aspnet")
' Get the section.
Dim traceSection As System.Web.Configuration.TraceSection = _
CType(configuration.GetSection("system.web/trace"), _
System.Web.Configuration.TraceSection)
' 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
configuration.Save()
Console.WriteLine("** Configuration updated.")
Else
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
End Namespace ' Samples.Aspnet.SystemWebConfiguration
Kommentarer
Klassen TraceSection ger ett sätt att programmatiskt komma åt och ändra innehållet i avsnittet för konfigurationsfil trace . Avsnittet trace konfigurerar ASP.NET spårningsfunktioner och styr hur spårningsresultat samlas in, lagras och visas.
När spårning är aktiverat genererar varje sidbegäran spårningsmeddelanden som kan läggas till i sidutdata eller lagras i en programspårningslogg. Du kan använda ASP.NET trace viewer (Trace.axd) för att visa innehållet i spårningsloggen.
Konstruktorer
| Name | Description |
|---|---|
| TraceSection() |
Initierar en ny instans av klassen med hjälp av TraceSection standardinställningar. |
Egenskaper
| Name | Description |
|---|---|
| CurrentConfiguration |
Hämtar en referens till den översta instansen Configuration som representerar konfigurationshierarkin som den aktuella ConfigurationElement instansen tillhör. (Ärvd från ConfigurationElement) |
| ElementInformation |
Hämtar ett ElementInformation objekt som innehåller den icke-anpassningsbara informationen och funktionerna i ConfigurationElement objektet. (Ärvd från ConfigurationElement) |
| ElementProperty |
Hämtar objektet ConfigurationElementProperty som representerar ConfigurationElement själva objektet. (Ärvd från ConfigurationElement) |
| Enabled |
Hämtar eller anger ett värde som anger om ASP.NET spårningstjänsten är aktiverad. |
| EvaluationContext |
Hämtar ContextInformation-objektet för ConfigurationElement-objektet. (Ärvd från ConfigurationElement) |
| HasContext |
Hämtar ett värde som anger om egenskapen CurrentConfiguration är |
| Item[ConfigurationProperty] |
Hämtar eller anger en egenskap eller ett attribut för det här konfigurationselementet. (Ärvd från ConfigurationElement) |
| Item[String] |
Hämtar eller anger en egenskap, ett attribut eller ett underordnat element i det här konfigurationselementet. (Ärvd från ConfigurationElement) |
| LocalOnly |
Hämtar eller anger ett värde som anger om ASP.NET spårningsvisare (Trace.axd) endast är tillgänglig för begäranden från värdwebbservern. |
| LockAllAttributesExcept |
Hämtar samlingen med låsta attribut. (Ärvd från ConfigurationElement) |
| LockAllElementsExcept |
Hämtar samlingen med låsta element. (Ärvd från ConfigurationElement) |
| LockAttributes |
Hämtar samlingen med låsta attribut. (Ärvd från ConfigurationElement) |
| LockElements |
Hämtar samlingen med låsta element. (Ärvd från ConfigurationElement) |
| LockItem |
Hämtar eller anger ett värde som anger om elementet är låst. (Ärvd från ConfigurationElement) |
| MostRecent |
Hämtar eller anger ett värde som anger om de senaste begärandena alltid lagras på servern. |
| PageOutput |
Hämtar eller anger ett värde som anger om ASP.NET spårningsinformation läggs till i utdata för varje sida. |
| Properties |
Hämtar samlingen med egenskaper. (Ärvd från ConfigurationElement) |
| RequestLimit |
Hämtar eller anger ett värde som anger det maximala antalet begäranden till programmet som ASP.NET lagrar spårningsinformation för. |
| SectionInformation |
Hämtar ett SectionInformation objekt som innehåller den icke-anpassningsbara informationen och funktionerna i ConfigurationSection objektet. (Ärvd från ConfigurationSection) |
| TraceMode |
Hämtar eller anger i vilken ordning ASP.NET spårningsinformation visas. |
| WriteToDiagnosticsTrace |
Hämtar eller anger ett värde som anger om meddelandena som skickas via sidspårningen vidarebefordras till en instans av Trace klassen. |
Metoder
| Name | Description |
|---|---|
| DeserializeElement(XmlReader, Boolean) |
Läser XML från konfigurationsfilen. (Ärvd från ConfigurationElement) |
| DeserializeSection(XmlReader) |
Läser XML från konfigurationsfilen. (Ärvd från ConfigurationSection) |
| Equals(Object) |
Jämför den aktuella ConfigurationElement instansen med det angivna objektet. (Ärvd från ConfigurationElement) |
| GetHashCode() |
Hämtar ett unikt värde som representerar den aktuella ConfigurationElement instansen. (Ärvd från ConfigurationElement) |
| GetRuntimeObject() |
Returnerar ett anpassat objekt när det åsidosättas i en härledd klass. (Ärvd från ConfigurationSection) |
| GetTransformedAssemblyString(String) |
Returnerar den transformerade versionen av det angivna sammansättningsnamnet. (Ärvd från ConfigurationElement) |
| GetTransformedTypeString(String) |
Returnerar den transformerade versionen av det angivna typnamnet. (Ärvd från ConfigurationElement) |
| GetType() |
Hämtar den aktuella instansen Type . (Ärvd från Object) |
| Init() |
Anger objektets ConfigurationElement ursprungliga tillstånd. (Ärvd från ConfigurationElement) |
| InitializeDefault() |
Används för att initiera en standarduppsättning med värden för ConfigurationElement objektet. (Ärvd från ConfigurationElement) |
| IsModified() |
Anger om det här konfigurationselementet har ändrats sedan det senast sparades eller lästes in när det implementerades i en härledd klass. (Ärvd från ConfigurationSection) |
| IsReadOnly() |
Hämtar ett värde som anger om objektet ConfigurationElement är skrivskyddat. (Ärvd från ConfigurationElement) |
| ListErrors(IList) |
Lägger till felen invalid-property i det här ConfigurationElement objektet, och i alla underelement, i den överförda listan. (Ärvd från ConfigurationElement) |
| MemberwiseClone() |
Skapar en ytlig kopia av den aktuella Object. (Ärvd från Object) |
| OnDeserializeUnrecognizedAttribute(String, String) |
Hämtar ett värde som anger om ett okänt attribut påträffas under deserialiseringen. (Ärvd från ConfigurationElement) |
| OnDeserializeUnrecognizedElement(String, XmlReader) |
Hämtar ett värde som anger om ett okänt element påträffas under deserialiseringen. (Ärvd från ConfigurationElement) |
| OnRequiredPropertyNotFound(String) |
Utlöser ett undantag när en obligatorisk egenskap inte hittas. (Ärvd från ConfigurationElement) |
| PostDeserialize() |
Anropas efter deserialisering. (Ärvd från ConfigurationElement) |
| PreSerialize(XmlWriter) |
Anropas före serialisering. (Ärvd från ConfigurationElement) |
| Reset(ConfigurationElement) |
Återställer objektets interna tillstånd ConfigurationElement , inklusive låsen och egenskapssamlingarna. (Ärvd från ConfigurationElement) |
| ResetModified() |
Återställer värdet för metoden till IsModified() när den |
| SerializeElement(XmlWriter, Boolean) |
Skriver innehållet i det här konfigurationselementet till konfigurationsfilen när det implementeras i en härledd klass. (Ärvd från ConfigurationElement) |
| SerializeSection(ConfigurationElement, String, ConfigurationSaveMode) |
Skapar en XML-sträng som innehåller en icke-komprimerad vy av ConfigurationSection objektet som ett enda avsnitt för att skriva till en fil. (Ärvd från ConfigurationSection) |
| SerializeToXmlElement(XmlWriter, String) |
Skriver de yttre taggarna för det här konfigurationselementet till konfigurationsfilen när det implementeras i en härledd klass. (Ärvd från ConfigurationElement) |
| SetPropertyValue(ConfigurationProperty, Object, Boolean) |
Anger en egenskap till det angivna värdet. (Ärvd från ConfigurationElement) |
| SetReadOnly() |
Anger egenskapen IsReadOnly() för ConfigurationElement objektet och alla underelement. (Ärvd från ConfigurationElement) |
| ShouldSerializeElementInTargetVersion(ConfigurationElement, String, FrameworkName) |
Anger om det angivna elementet ska serialiseras när konfigurationsobjekthierarkin serialiseras för den angivna målversionen av .NET Framework. (Ärvd från ConfigurationSection) |
| ShouldSerializePropertyInTargetVersion(ConfigurationProperty, String, FrameworkName, ConfigurationElement) |
Anger om den angivna egenskapen ska serialiseras när konfigurationsobjekthierarkin serialiseras för den angivna målversionen av .NET Framework. (Ärvd från ConfigurationSection) |
| ShouldSerializeSectionInTargetVersion(FrameworkName) |
Anger om den aktuella ConfigurationSection-instansen ska serialiseras när konfigurationsobjekthierarkin serialiseras för den angivna målversionen av .NET Framework. (Ärvd från ConfigurationSection) |
| ToString() |
Returnerar en sträng som representerar det aktuella objektet. (Ärvd från Object) |
| Unmerge(ConfigurationElement, ConfigurationElement, ConfigurationSaveMode) |
Ändrar objektet ConfigurationElement för att ta bort alla värden som inte ska sparas. (Ärvd från ConfigurationElement) |