トレース <tracing>

概要

<tracing> セクション グループには、構成した失敗した要求トレース設定が含まれ、インストール中またはインターネット インフォメーション サービス (IIS) 7 Web サーバーで提供されるトレース プロバイダー定義が含まれます。

要求ベースのトレースを使用すると、サーバーで発生している問題を再現できる場合に、要求に付随して発生する処理内容と、その発生理由を正確に把握する方法が提供されます。 一部の要求のパフォーマンス低下、他の要求での認証関連のエラー、Active Server Pages (ASP) または ASP.NET からの HTTP 500 状態コード エラーなどの問題は、問題が発生したときに問題のトレースをキャプチャしない限り、トラブルシューティングが非常に困難な場合があります。 失敗した要求のトレースは、要求のトレース イベントをバッファーに格納し、指定したエラー定義に基づいて要求が失敗した場合にのみ、それをディスクにフラッシュするように設計されています。

IIS 7 では、トレース モジュールをインストールして有効にした後にのみ、これらのメッセージが表示されます。 これらのメッセージとその他のトレース情報は、失敗したイベント トレース ログ ファイルであることを示す特別なファイルに格納されます。 これらのファイルを Web ブラウザーで開き、IIS によって生成されたトレース イベント、サード パーティ製モジュールによって生成されたカスタム トレース イベント、またはその両方を確認できます。 既定では、IIS 7 はこれらのファイルを %systemroot%\inetpub\logs\FailedReqLogFiles フォルダーに格納します。

<tracing> セクションには、<traceFailedRequests> 要素と <traceProviderDefinition> 要素が含まれています。 最初の要素は、Web サイトまたはアプリケーションの失敗した要求トレースを構成し、2 番目の要素はサーバーで使用できるトレース プロバイダーを定義します。 既定では、IIS 7 には、ASP、ASP.NET、インターネット サーバー API (ISAPI) 拡張機能、Web サーバー自体のトレース プロバイダーが含まれています。 カスタム トレース プロバイダーを含めることもできます。

互換性

バージョン メモ
IIS 10.0 <tracing> 要素は、IIS 10.0 では変更されませんでした。
IIS 8.5 <tracing> 要素は、IIS 8.5 では変更されませんでした。
IIS 8.0 <tracing> 要素は IIS 8.0 では変更されませんでした。
IIS 7.5 <tracing> 要素は、IIS 7.5 では変更されませんでした。
IIS 7.0 <tracing> 要素が IIS 7.0 で導入されました。
IIS 6.0 該当なし

段取り

IIS 7 以降の既定のインストールが完了したら、失敗した要求トレースを使用するためにトレース役割サービスをインストールする必要があります。 役割サービスをインストールした後も、サイト レベル、アプリケーション レベル、またはディレクトリ レベルで失敗した要求トレースを有効にする必要があります。

Windows Server 2012 または Windows Server 2012 R2

  1. タスク バーで [サーバー マネージャー]をクリックします。
  2. [サーバー マネージャー] で、[管理] メニューを選択し、[役割と機能の追加] を選択します。
  3. 役割と機能の追加ウィザードで、[次へ] を選択します。 [インストールの種類] を選択し、[次へ] を選択します。 対象サーバーを選択し、[次へ] を選択します。
  4. [サーバーの役割] ページで、[Web サーバー (IIS)][Web サーバー] の順に展開し、[正常性と診断] を展開して、[トレース] を選択します。 次へ をクリックします。
    Screenshot of the Server Roles page. Tracing is highlighted in the expanded menu.
  5. [機能の選択] ページで、[次へ] をクリックします。
  6. [インストール オプションの確認] ページで、[インストール] をクリックします。
  7. [結果] ページで、 [閉じる]をクリックします。

Windows 8 または Windows 8.1

  1. [スタート] 画面で、ポインターを左下隅まで移動し、[スタート] ボタンを右クリックし、[コントロール パネル] を選択します。
  2. [コントロール パネル][プログラムと機能] を選択し、[Windows の機能の有効化または無効化] を選択します。
  3. [インターネット インフォメーション サービス] を展開し、[World Wide Web サービス] を展開し、[正常性と診断] を展開して、[トレース] を選択します。
    Screenshot of the Windows Features dialog box. Tracing is highlighted in the drop down menu.- [OK] を選択します。
  4. 閉じるをクリックします。

Windows Server 2008 または Windows Server 2008 R2

  1. タスク バーで [スタート] を選択し、[管理ツール] をポイントして、[サーバー マネージャー] を選択します。
  2. [サーバー マネージャー] 階層ウィンドウで [ロール] を展開し、[Web サーバー (IIS)] を選択します。
  3. [Web サーバー (IIS)] ウィンドウで、[役割サービス] セクションまでスクロールし、[役割サービスの追加] を選択します。
  4. 役割サービスの追加ウィザード[役割サービスの選択] ページで、[トレース] を選択し、[次へ] を選択します。
    Screenshot of the Add Role Services wizard displaying the Role Services page. Tracing is highlighted in the menu.
  5. [インストール オプションの確認] ページで、[インストール] をクリックします。
  6. [結果] ページで、 [閉じる]をクリックします。

Windows Vista または Windows 7

  1. タスク バーで、[スタート][コントロール パネル] の順に選択します。
  2. [コントロール パネル][プログラムと機能] を選択し、[Windows の機能の有効化または無効化] を選択します。
  3. [インターネット インフォメーション サービス][World Wide Web サービス][正常性と診断] の順に展開します。
  4. [トレース] を選択して、[OK] を選択します。
    Screenshot of the Windows Features dialog box. Tracing is highlighted in the expanded menu.

操作方法

トレースを有効にする方法

  1. インターネット インフォメーション サービス (IIS) マネージャーを開きます。

    • Windows Server 2012 または Windows Server 2012 R2 を使用している場合:

      • タスク バーで、[サーバー マネージャー] を選択し、[ツール][インターネット インフォメーション サービス (IIS) マネージャー] の順に選択します。
    • Windows 8 または Windows 8.1 を使用している場合:

      • Windows キーを押しながら文字 X を押し、[コントロール パネル] を選択します。
      • [管理ツール] を選択し、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
    • Windows Server 2008 または Windows Server 2008 R2 を使用している場合:

      • タスク バーで、[スタート] ボタンを選択し、[管理ツール][インターネット インフォメーション サービス (IIS) マネージャー] の順に選択します。
    • Windows Vista または Windows 7 を使用している場合:

      • タスク バーで、[スタート][コントロール パネル] の順に選択します。
      • [管理ツール] をダブルクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
  2. [接続] ウィンドウで、失敗した要求のトレースを構成するサーバー接続、サイト、アプリケーション、またはディレクトリを選択します。

  3. [操作] ウィンドウで、[失敗した要求のトレース] を選択します。
    Screenshot of the I I S Manager window displaying the Default Web Site Home page.

  4. [Web サイトの失敗した要求トレース設定の編集] ダイアログ ボックスで、トレースを有効にするための [有効化] チェック ボックスをオンにし、[ディレクトリ] に失敗した要求ログ ファイルを格納する場所を既定値のままにするか、新しいディレクトリを入力し、[トレース ファイルの最大数] ボックスに格納する失敗した要求トレース ファイルの数を入力し、[OK] を選択します。
    Screenshot of the Edit Web Site Failed Request Tracing Settings dialog box.

エラー定義を構成する方法

  1. インターネット インフォメーション サービス (IIS) マネージャーを開きます。

    • Windows Server 2012 または Windows Server 2012 R2 を使用している場合:

      • タスク バーで、[サーバー マネージャー] を選択し、[ツール][インターネット インフォメーション サービス (IIS) マネージャー] の順に選択します。
    • Windows 8 または Windows 8.1 を使用している場合:

      • Windows キーを押しながら文字 X を押し、[コントロール パネル] を選択します。
      • [管理ツール] を選択し、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
    • Windows Server 2008 または Windows Server 2008 R2 を使用している場合:

      • タスク バーで、[スタート] ボタンを選択し、[管理ツール][インターネット インフォメーション サービス (IIS) マネージャー] の順に選択します。
    • Windows Vista または Windows 7 を使用している場合:

      • タスク バーで、[スタート][コントロール パネル] の順に選択します。
      • [管理ツール] をダブルクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
  2. [接続] ウィンドウで、失敗した要求のトレースを構成する接続、サイト、アプリケーション、またはディレクトリに移動します。

  3. ホーム ウィンドウの [失敗した要求トレースの規則] をダブルクリックします。
    Screenshot of the I I S Manager displaying the Default Web Site Home page. The icon for Failed Request Tracing Rules is highlighted.

  4. [操作] ウィンドウで、[追加] を選択します。

  5. [失敗した要求トレース規則の追加] ウィザードの [トレースするコンテンツの指定] ページで、トレースするコンテンツ タイプを選択し、[次へ] を選択します。
    Screenshot of the Add Failed Request Tracing Rule wizard displaying the Specify Content to Trace page.

  6. [トレース条件の定義] ページでトレースする条件を選択し、[次へ] を選択します。 トレース条件には、状態コードの任意の組み合わせ、要求に費やされる時間の上限、またはイベントの重大度を含めることができます。 すべての条件を指定すると、最初に満たされた条件によって、失敗した要求トレース ログ ファイルが生成されます。
    Screenshot of the Add Failed Request Tracing Rule wizard displaying the Define Content to Trace page.

  7. [トレース プロバイダーの選択] ページで、[プロバイダー] に 1 つ以上のトレース プロバイダーを選択します。
    Screenshot of the Add Failed Request Tracing Rule wizard displaying the Select Trace Providers page.

  8. [トレース プロバイダーの選択] ページで、[詳細度] に 1 つ以上の詳細レベルを選択します。
    Screenshot of the Add Failed Request Tracing Rule wizard displaying the Select Trace Providers page. W W W Server and Warnings are selected.

  9. 手順 8 で ASPNET または WWW Server トレース プロバイダーを選択した場合は、[トレース プロバイダーの選択] ページの [領域] で、プロバイダーがトレースする機能領域を 1 つ以上選択します。

  10. [完了] をクリックします。

構成

<tracing> セクション グループは、ApplicationHost.config ファイルのサーバー レベルで構成することも、Web.config ファイルのサイト レベル、アプリケーション レベル、またはディレクトリ レベルで構成することもできます。

属性

なし。

子要素

要素 説明
traceFailedRequests 省略可能な要素です。

Web サーバーで失敗した要求をトレースするための設定が含まれます。
traceProviderDefinitions 省略可能な要素です。

Web サーバーで使用されるトレース プロバイダーを定義します。

構成サンプル

次の構成例では、ApplicationHost.config ファイルのサーバー レベルでトレースを構成します。 すべての .aspx ファイルのトレースを設定し、<traceAreas> 要素を使用して ASPNET プロバイダーを設定し、すべての ASP.NET 領域に対してトレースを実行します。これらの領域は InfrastructureModulePageAppServices です。 また、このサンプルでは verbosity 属性を使用して、トレース ファイルに返される情報の量を warning に設定します。 最後に、このサンプルでは、<failureDefinitions> 要素を使用して、HTTP 404 状態コードを生成する要求のみをトレースします。

<tracing>
   <traceFailedRequests>
      <add path="*.aspx">
         <traceAreas>
            <add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Warning" />
         </traceAreas>
         <failureDefinitions statusCodes="404" />
      </add>
   </traceFailedRequests>
</tracing>

サンプル コード

次の例では、*.aspx ページに対するすべての要求の ASP.NET コンテンツで HTTP 500 エラーの詳細な失敗した要求のトレースを有効にします。

AppCmd.exe

appcmd.exe set config "Contoso" -section:system.webServer/tracing/traceFailedRequests /+"[path='*.aspx']" 

appcmd.exe set config "Contoso" -section:system.webServer/tracing/traceFailedRequests /+"[path='*.aspx'].traceAreas.[provider='ASPNET',areas='Infrastructure,Module,Page,AppServices',verbosity='Verbose']" 

appcmd.exe set config "Contoso" -section:system.webServer/tracing/traceFailedRequests /[path='*.aspx'].failureDefinitions.statusCodes:"500"

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.GetWebConfiguration("Contoso");
         ConfigurationSection traceFailedRequestsSection = config.GetSection("system.webServer/tracing/traceFailedRequests");
         ConfigurationElementCollection traceFailedRequestsCollection = traceFailedRequestsSection.GetCollection();

         ConfigurationElement addElement = traceFailedRequestsCollection.CreateElement("add");
         addElement["path"] = @"*.aspx";

         ConfigurationElementCollection traceAreasCollection = addElement.GetCollection("traceAreas");
         ConfigurationElement addElement1 = traceAreasCollection.CreateElement("add");
         addElement1["provider"] = @"ASPNET";
         addElement1["areas"] = @"Infrastructure,Module,Page,AppServices";
         addElement1["verbosity"] = @"Verbose";
         traceAreasCollection.Add(addElement1);

         ConfigurationElement failureDefinitionsElement = addElement.GetChildElement("failureDefinitions");
         failureDefinitionsElement["statusCodes"] = @"500";
         traceFailedRequestsCollection.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.GetWebConfiguration("Contoso")
      Dim traceFailedRequestsSection As ConfigurationSection = config.GetSection("system.webServer/tracing/traceFailedRequests")
      Dim traceFailedRequestsCollection As ConfigurationElementCollection = traceFailedRequestsSection.GetCollection

      Dim addElement As ConfigurationElement = traceFailedRequestsCollection.CreateElement("add")
      addElement("path") = "*.aspx"
      Dim traceAreasCollection As ConfigurationElementCollection = addElement.GetCollection("traceAreas")
      Dim addElement1 As ConfigurationElement = traceAreasCollection.CreateElement("add")
      addElement1("provider") = "ASPNET"
      addElement1("areas") = "Infrastructure,Module,Page,AppServices"
      addElement1("verbosity") = "Verbose"
      traceAreasCollection.Add(addElement1)

      Dim failureDefinitionsElement As ConfigurationElement = addElement.GetChildElement("failureDefinitions")
      failureDefinitionsElement("statusCodes") = "500"
      traceFailedRequestsCollection.Add(addElement)

      serverManager.CommitChanges()
   End Sub
End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Contoso";
var traceFailedRequestsSection = adminManager.GetAdminSection("system.webServer/tracing/traceFailedRequests", "MACHINE/WEBROOT/APPHOST/Contoso");
var traceFailedRequestsCollection = traceFailedRequestsSection.Collection;

var addElement = traceFailedRequestsCollection.CreateNewElement("add");
addElement.Properties.Item("path").Value = "*.aspx";
var traceAreasCollection = addElement.ChildElements.Item("traceAreas").Collection;

var addElement1 = traceAreasCollection.CreateNewElement("add");
addElement1.Properties.Item("provider").Value = "ASPNET";
addElement1.Properties.Item("areas").Value = "Infrastructure,Module,Page,AppServices";
addElement1.Properties.Item("verbosity").Value = "Verbose";
traceAreasCollection.AddElement(addElement1);

var failureDefinitionsElement = addElement.ChildElements.Item("failureDefinitions");
failureDefinitionsElement.Properties.Item("statusCodes").Value = "500";
traceFailedRequestsCollection.AddElement(addElement);

adminManager.CommitChanges();

VBScript

Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Contoso"
Set traceFailedRequestsSection = adminManager.GetAdminSection("system.webServer/tracing/traceFailedRequests", "MACHINE/WEBROOT/APPHOST/Contoso")
Set traceFailedRequestsCollection = traceFailedRequestsSection.Collection

Set addElement = traceFailedRequestsCollection.CreateNewElement("add")
addElement.Properties.Item("path").Value = "*.aspx"
Set traceAreasCollection = addElement.ChildElements.Item("traceAreas").Collection

Set addElement1 = traceAreasCollection.CreateNewElement("add")
addElement1.Properties.Item("provider").Value = "ASPNET"
addElement1.Properties.Item("areas").Value = "Infrastructure,Module,Page,AppServices"
addElement1.Properties.Item("verbosity").Value = "Verbose"
traceAreasCollection.AddElement addElement1

Set failureDefinitionsElement = addElement.ChildElements.Item("failureDefinitions")
failureDefinitionsElement.Properties.Item("statusCodes").Value = "500"
traceFailedRequestsCollection.AddElement addElement

adminManager.CommitChanges()