Trace Provider Definitions <traceProviderDefinitions>

Overview

The <traceProviderDefinitions> element allows you to define a collection of trace providers available on the Internet Information Services (IIS) 7 server. A trace provider is an application or operating system component that generates trace messages or trace events. When you install the Tracing role service on IIS 7, by default, IIS installs the WWW Server trace provider, which is associated with the IIS 7 server, the ASP trace provider, and the ISAPI Extension trace provider. If you install ASP.NET 2.0 on the server, IIS 7 automatically adds the ASPNET trace provider to the trace provider definition collection. IIS defines each trace provider in an <add> element within the <traceProviderDefinitions> element.

You can add custom trace providers to the server by adding an <add> element that defines that trace provider. You can include a <remove> element in the <traceProviderDefinitions> element to remove a single trace provider inherited from a configuration file higher in the configuration hierarchy. You can use the <clear> element to remove all inherited trace providers.

Compatibility

Version Notes
IIS 7.5 The <traceProviderDefinitions> element was not modified in IIS 7.5.
IIS 7.0 The <traceProviderDefinitions> element was introduced in IIS 7.0.
IIS 6.0 N/A

Setup

After you finish the default installation of IIS 7, you must install the tracing role service to use failed request tracing. After you install the role service, you still must enable failed request tracing at the site level, application level, or directory level.

Windows Server 2008 or Windows Server 2008 R2

  1. On the taskbar, click Start, point to Administrative Tools, and then click Server Manager.
  2. In the Server Manager hierarchy pane, expand Roles, and then click Web Server (IIS).
  3. In the Web Server (IIS) pane, scroll to the Role Services section, and then click Add Role Services.
  4. On the Select Role Services page of the Add Role Services Wizard, select Tracing, and then click Next.

  5. On the Confirm Installation Selections page, click Install.
  6. On the Results page, click Close.

Windows Vista or Windows 7

  1. On the taskbar, click Start, and then click Control Panel.
  2. In Control Panel, click Programs and Features, and then click Turn Windows Features on or off.
  3. Expand Internet Information Services, then World Wide Web Services, then Health and Diagnostics.
  4. Select Tracing, and then click OK.

How To

There is no user interface for adding trace providers for IIS 7. For examples of how to add trace providers programmatically, see the Code Samples section of this document.

Configuration

You can configure the <traceProviderDefinitions> element at the server level in the ApplicationHost.config file or at the site level, application level, or directory level in the appropriate Web.config file.

Attributes

None.

Child Elements

Element Description
add Optional element.

Adds a trace provider to the collection of trace providers.
clear Optional element.

Removes all references to trace providers from the trace provider collection.
remove Optional element.

Removes a reference to a trace provider from the trace provider collection.

Configuration Sample

The following default <traceProviderDefinitions> element is configured in the root ApplicationHost.config file in IIS 7.0.

<traceProviderDefinitions>
   <add name="WWW Server" guid="{3a2a4e84-4c21-4981-ae10-3fda0d9b0f83}">
      <areas>
         <clear />
         <add name="Authentication" value="2" />
         <add name="Security" value="4" />
         <add name="Filter" value="8" />
         <add name="StaticFile" value="16" />
         <add name="CGI" value="32" />
         <add name="Compression" value="64" />
         <add name="Cache" value="128" />
         <add name="RequestNotifications" value="256" />
         <add name="Module" value="512" />
      </areas>
   </add>
   <add name="ASP" guid="{06b94d9a-b15e-456e-a4ef-37c984a2cb4b}">
      <areas>
         <clear />
      </areas>
   </add>
   <add name="ISAPI Extension" guid="{a1c2040e-8840-4c31-ba11-9871031a19ea}">
      <areas>
         <clear />
      </areas>
   </add>
   <add name="ASPNET" guid="{AFF081FE-0247-4275-9C4E-021F3DC1DA35}">
      <areas>
         <add name="Infrastructure" value="1" />
         <add name="Module" value="2" />
         <add name="Page" value="4" />
         <add name="AppServices" value="8" />
      </areas>
   </add>
</traceProviderDefinitions>

Sample Code

The following examples add a custom trace provider with two trace areas to the list that is defined in the global <traceProviderDefinitions> collection.

AppCmd.exe

appcmd.exe set config -section:system.webServer/tracing/traceProviderDefinitions /+"[name='MyTraceProvider',guid='{00000000-0000-0000-0000-00000000000}']" /commit:apphost

appcmd.exe set config -section:system.webServer/tracing/traceProviderDefinitions /+"[guid='{00000000-0000-0000-0000-00000000000}'].areas.[name='ProviderAreaOne',value='0']" /commit:apphost

appcmd.exe set config -section:system.webServer/tracing/traceProviderDefinitions /+"[guid='{00000000-0000-0000-0000-00000000000}'].areas.[name='ProviderAreaTwo',value='1']" /commit:apphost

Note: You must be sure to set the commit parameter to apphost when you use AppCmd.exe to configure these settings. This commits the configuration settings to the appropriate location section in the ApplicationHost.config file.

C#

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample
{
   private static void Main()
   {
      using (ServerManager serverManager = new ServerManager())
      {
         Configuration config = serverManager.GetApplicationHostConfiguration();
         ConfigurationSection traceProviderDefinitionsSection = config.GetSection("system.webServer/tracing/traceProviderDefinitions");
         ConfigurationElementCollection traceProviderDefinitionsCollection = traceProviderDefinitionsSection.GetCollection();

         ConfigurationElement addElement = traceProviderDefinitionsCollection.CreateElement("add");
         addElement["name"] = @"MyTraceProvider";
         addElement["guid"] = @"{00000000-0000-0000-0000-00000000000}";
         ConfigurationElementCollection areasCollection = addElement.GetCollection("areas");

         ConfigurationElement addElement1 = areasCollection.CreateElement("add");
         addElement1["name"] = @"ProviderAreaOne";
         addElement1["value"] = 0;
         areasCollection.Add(addElement1);

         ConfigurationElement addElement2 = areasCollection.CreateElement("add");
         addElement2["name"] = @"ProviderAreaTwo";
         addElement2["value"] = 1;
         areasCollection.Add(addElement2);

         traceProviderDefinitionsCollection.Add(addElement);
         serverManager.CommitChanges();
      }
   }
}

VB.NET

Imports System
Imports System.Text
Imports Microsoft.Web.Administration

Module Sample
   Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetApplicationHostConfiguration
      Dim traceProviderDefinitionsSection As ConfigurationSection = config.GetSection("system.webServer/tracing/traceProviderDefinitions")
      Dim traceProviderDefinitionsCollection As ConfigurationElementCollection = traceProviderDefinitionsSection.GetCollection

      Dim addElement As ConfigurationElement = traceProviderDefinitionsCollection.CreateElement("add")
      addElement("name") = "MyTraceProvider"
      addElement("guid") = "{00000000-0000-0000-0000-00000000000}"
      Dim areasCollection As ConfigurationElementCollection = addElement.GetCollection("areas")

      Dim addElement1 As ConfigurationElement = areasCollection.CreateElement("add")
      addElement1("name") = "ProviderAreaOne"
      addElement1("value") = 0
      areasCollection.Add(addElement1)

      Dim addElement2 As ConfigurationElement = areasCollection.CreateElement("add")
      addElement2("name") = "ProviderAreaTwo"
      addElement2("value") = 1
      areasCollection.Add(addElement2)

      traceProviderDefinitionsCollection.Add(addElement)
      serverManager.CommitChanges()
   End Sub
End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var traceProviderDefinitionsSection = adminManager.GetAdminSection("system.webServer/tracing/traceProviderDefinitions", "MACHINE/WEBROOT/APPHOST");
var traceProviderDefinitionsCollection = traceProviderDefinitionsSection.Collection;

var addElement = traceProviderDefinitionsCollection.CreateNewElement("add");
addElement.Properties.Item("name").Value = "MyTraceProvider";
addElement.Properties.Item("guid").Value = "{00000000-0000-0000-0000-00000000000}";
var areasCollection = addElement.ChildElements.Item("areas").Collection;

var addElement1 = areasCollection.CreateNewElement("add");
addElement1.Properties.Item("name").Value = "ProviderAreaOne";
addElement1.Properties.Item("value").Value = 0;
areasCollection.AddElement(addElement1);

var addElement2 = areasCollection.CreateNewElement("add");
addElement2.Properties.Item("name").Value = "ProviderAreaTwo";
addElement2.Properties.Item("value").Value = 1;
areasCollection.AddElement(addElement2);

traceProviderDefinitionsCollection.AddElement(addElement);
adminManager.CommitChanges();

VBScript

Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set traceProviderDefinitionsSection = adminManager.GetAdminSection("system.webServer/tracing/traceProviderDefinitions", "MACHINE/WEBROOT/APPHOST")
Set traceProviderDefinitionsCollection = traceProviderDefinitionsSection.Collection

Set addElement = traceProviderDefinitionsCollection.CreateNewElement("add")
addElement.Properties.Item("name").Value = "MyTraceProvider"
addElement.Properties.Item("guid").Value = "{00000000-0000-0000-0000-00000000000}"
Set areasCollection = addElement.ChildElements.Item("areas").Collection

Set addElement1 = areasCollection.CreateNewElement("add")
addElement1.Properties.Item("name").Value = "ProviderAreaOne"
addElement1.Properties.Item("value").Value = 0
areasCollection.AddElement addElement1

Set addElement2 = areasCollection.CreateNewElement("add")
addElement2.Properties.Item("name").Value = "ProviderAreaTwo"
addElement2.Properties.Item("value").Value = 1
areasCollection.AddElement addElement2

traceProviderDefinitionsCollection.AddElement addElement
adminManager.CommitChanges()
Deprecated Elements