HTTP トレース <httpTracing>

  • 概要
  • 互換性
  • セットアップ
  • 方法
  • 構成
  • サンプル コード

概要

<httpTracing> 要素を使用すると、IIS 着信要求に要求ベースのイベントのトレースを構成できます。また、この要素には、<add> 要素のコレクションを格納する <traceUrls> 要素が格納されます。これらの各要素では、トレースを有効にするために一意の URL が定義されます。

: Event Tracing for Windows (ETW) は、オペレーティング システムによって提供される汎用の高速トレース機能です。ETW は、カーネルに実装されたバッファー処理とログ記録のメカニズムを使用して、ユーザーモードのアプリケーションとカーネルモードのデバイス ドライバーの両方によって起動されたイベントにトレース メカニズムを提供します。さらに、ログ記録を動的に有効化および無効化する機能を提供して、コンピューターやアプリケーションの再起動なしに、運用環境で詳細なトレースを簡単に行えるようにします。ログ記録メカニズムでは、非同期ライター スレッドによってディスクに書き込まれるプロセッサ単位のバッファーを使用します。これにより、大規模なサーバー アプリケーションは、最小限の妨害でイベントを書き込むことができます。

互換性

  IIS 7.0 IIS 6.0
注意 <httpTracing> は IIS 7.0 で新たに導入された要素です。

なし

セットアップ

<httpTracing> 要素は、IIS 7.0 の既定のインストールに含まれています。

方法

IIS 7.0 では、<httpTracing> 要素を構成するためのユーザー インターフェイスはありません。<httpTracing> 要素にプログラムを使用してアクセスする方法の例については、このドキュメントの「サンプル コード」セクションを参照してください。

構成

サーバー レベルでの <httpTracing> 要素の構成は ApplicationHost.config ファイルで、サイト、アプリケーション、またはディレクトリ レベルでのこの要素の構成は Web.config ファイルで、それぞれ設定できます。

属性

なし。

子要素

要素 説明
traceUrls オプションの要素。

要求ベースの ETW トレースを有効にする URL を指定します。

構成サンプル

次の例を Default Web Site のルートにある Web.config ファイルに配置すると、IIS 7.0 に付属するサンプル ホーム ページのトレースが有効になります。

<configuration>
   <system.webServer>
      <httpTracing>
         <traceUrls>
            <add value="/iisstart.htm" />
         </traceUrls>

      </httpTracing>
   </system.webServer>
</configuration>

サンプル コード

次の例では、Contoso という Web サイトの <traceUrls> コレクションにエントリを追加することにより、この Web サイト上で、 IIS 7.0 に付属するサンプル ホーム ページのトレースを有効にします。

AppCmd.exe

appcmd.exe set config "Contoso" -section:system.webServer/httpTracing /+"traceUrls.[value='/iisstart.htm']" /commit:apphost

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 httpTracingSection = config.GetSection("system.webServer/httpTracing", "Contoso");
         ConfigurationElementCollection traceUrlsCollection = httpTracingSection.GetCollection("traceUrls");

         ConfigurationElement addElement = traceUrlsCollection.CreateElement("add");
         addElement["value"] = @"/iisstart.htm";
         traceUrlsCollection.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 httpTracingSection As ConfigurationSection = config.GetSection("system.webServer/httpTracing", "Contoso")

      Dim traceUrlsCollection As ConfigurationElementCollection = httpTracingSection.GetCollection("traceUrls")
      Dim addElement As ConfigurationElement = traceUrlsCollection.CreateElement("add")
      addElement("value") = "/iisstart.htm"
      traceUrlsCollection.Add(addElement)

      serverManager.CommitChanges()
   End Sub
End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var httpTracingSection = adminManager.GetAdminSection("system.webServer/httpTracing", "MACHINE/WEBROOT/APPHOST/Contoso");

var traceUrlsCollection = httpTracingSection.ChildElements.Item("traceUrls").Collection;
var addElement = traceUrlsCollection.CreateNewElement("add");
addElement.Properties.Item("value").Value = "/iisstart.htm";
traceUrlsCollection.AddElement(addElement);

adminManager.CommitChanges();

VBScript

Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set httpTracingSection = adminManager.GetAdminSection("system.webServer/httpTracing", "MACHINE/WEBROOT/APPHOST/Contoso")

Set traceUrlsCollection = httpTracingSection.ChildElements.Item("traceUrls").Collection
Set addElement = traceUrlsCollection.CreateNewElement("add")
addElement.Properties.Item("value").Value = "/iisstart.htm"
traceUrlsCollection.AddElement addElement

adminManager.CommitChanges()