This topic has not yet been rated - Rate this topic

PresentationTraceSources Class

Updated: July 2010

Provides debug tracing support that is specifically targeted for Windows Presentation Foundation (WPF) applications.

System.Object
  System.Diagnostics.PresentationTraceSources

Namespace:  System.Diagnostics
Assembly:  WindowsBase (in WindowsBase.dll)
public static class PresentationTraceSources

The PresentationTraceSources type exposes the following members.

  Name Description
Public property Static member AnimationSource Gets an animation trace source.
Public property Static member DataBindingSource Gets a data-binding trace source.
Public property Static member DependencyPropertySource Gets a dependency property trace source.
Public property Static member DocumentsSource Gets a document trace source.
Public property Static member FreezableSource Gets a Freezable trace source.
Public property Static member HwndHostSource Gets an hwnd host trace source.
Public property Static member MarkupSource Gets a markup trace source.
Public property Static member NameScopeSource Gets a name scope trace source.
Public property Static member ResourceDictionarySource Gets a resource dictionary trace source.
Public property Static member RoutedEventSource Gets a routed event trace source.
Public property Static member ShellSource Gets a shell trace source.
Top
  Name Description
Public attached property TraceLevel Gets or sets a value that specifies the level of detail to trace about a particular object.
Top
  Name Description
Public method Static member GetTraceLevel Gets the value of the TraceLevel attached property for a specified element.
Public method Static member Refresh Refreshes trace sources, by forcing the app.config file to be re-read.
Public method Static member SetTraceLevel Sets the value of the PresentationTraceSourcesTraceLeve()l attached property to a specified element.
Top
  Name Description
Public field Static member TraceLevelProperty Identifies the TraceLevel attached property.
Top

Debug tracing is only available when a WPF application is running in full trust mode.

In order to enable tracing, you first must set a registry key, then you must configure trace sources.

  • To create the registry key, set a "ManagedTracing" reg_dword value to 1 under "HKeyCurrentUser\Software\Microsoft\Tracing\WPF".

  • To configure trace sources, create an application config file. This file has a .config extension, for example, XamlPad.exe.config.

Achieving optimal application performance requires forethought in application design and an understanding of best practices for Windows Presentation Foundation (WPF) application development. For more information, see Optimizing WPF Application Performance.

The following sample configuration file enables tracing of animations, writing the output to a text file called "debug.txt".

<configuration>
  <system.diagnostics>
    <sources>
      <source name="System.Windows.Media.Animation"
switchName="SourceSwitch" >
        <listeners>
          <add name="textListener" />
        </listeners>
      </source>
    </sources>
    <switches>
      <add name="SourceSwitch" value="All" />
    </switches>
    <sharedListeners>
      <add name="textListener"
           type="System.Diagnostics.TextWriterTraceListener"
           initializeData="Debug.txt" />
    </sharedListeners>
    <trace autoflush="true" indentsize="4"></trace>
  </system.diagnostics>
</configuration>

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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.

Date

History

Reason

July 2010

Removed incorrect statement and fixed example.

Customer feedback.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
WPF TraceSource Names

AnimationSource: System.Windows.Media.Animation
DataBindingSource: System.Windows.Data
DependencyPropertySource: System.Windows.DependencyProperty
DocumentsSource: System.Windows.Documents
FreezableSource: System.Windows.Freezable
HwndHostSource: System.Windows.Interop.HwndHost
MarkupSource: System.Windows.Markup
NameScopeSource: System.Windows.NameScope
ResourceDictionarySource: System.Windows.ResourceDictionary
RoutedEventSource: System.Windows.RoutedEvent
ShellSource: System.Windows.Shell

Configuring WPF Tracing

The TraceSource names above can be used in your app.config file. For example:

<system.diagnostics>
<switches>
<!-- Off, Critical, Error, Warning, Information, Verbose or All -->
<add name="WPF" value="Error" />
</switches>

<sharedListeners>
<add name="MyLogFile" type="System.Diagnostics.XmlWriterTraceListener"
initializeData="MyLogFile.xml"
traceOutputOptions="ProcessId, DateTime" />
</sharedListeners>

<sources>
<source name="System.Windows.Media.Animation" switchName="WPF" switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="MyLogFile" />
</listeners>
</source>
<source name="System.Windows.Data" switchName="WPF" switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="MyLogFile" />
</listeners>
</source>
<source name="System.Windows.DependencyProperty" switchName="WPF" switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="MyLogFile" />
</listeners>
</source>
<source name="System.Windows.Documents" switchName="WPF" switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="MyLogFile" />
</listeners>
</source>
<source name="System.Windows.Freezable" switchName="WPF" switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="MyLogFile" />
</listeners>
</source>
<source name="System.Windows.Interop.HwndHost" switchName="WPF" switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="MyLogFile" />
</listeners>
</source>
<source name="System.Windows.Markup" switchName="WPF" switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="MyLogFile" />
</listeners>
</source>
<source name="System.Windows.NameScope" switchName="WPF" switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="MyLogFile" />
</listeners>
</source>
<source name="System.Windows.ResourceDictionary" switchName="WPF" switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="MyLogFile" />
</listeners>
</source>
<source name="System.Windows.RoutedEvent" switchName="WPF" switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="MyLogFile" />
</listeners>
</source>
<source name="System.Windows.Shell" switchName="WPF" switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="MyLogFile" />
</listeners>
</source>
</sources>
</system.diagnostics>