失敗した要求のトレース <traceFailedRequests>

概要

<traceFailedRequests> 要素を使用すると、Web サイト、アプリケーション、またはディレクトリの失敗した要求トレースを構成できます。 この要素には、トレース規則を定義する <add> 要素のコレクションを含められます。各要素は、規則が適用される要求 URL の拡張、有効にするトレース プロバイダーと領域、この規則がイベントをログに記録する条件を指定します。

互換性

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

段取り

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

Windows Server 2012 または Windows Server 2012 R2

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

Windows 8 または Windows 8.1

  1. [スタート] 画面で、ポインターを左下隅まで移動し、[スタート] ボタンを右クリックし、[コントロール パネル] をクリックします。
  2. [コントロール パネル][プログラムと機能] をクリックし、次に [Windows の機能の有効化または無効化] をクリックします。
  3. [インターネット インフォメーション サービス] を展開し、[World Wide Web サービス] を展開し、[正常性と診断] を展開して、[トレース] を選びます。
    [トレース] が選択された状態で展開された [World Wide Web Services] ペインのスクリーンショット。 -- [OK] をクリックします。
  4. [閉じる] をクリックします。

Windows Server 2008 または Windows Server 2008 R2

  1. タスク バーで [スタート] をクリックし、[管理ツール] をポイントして、[サーバー マネージャ] をクリックします。
  2. [サーバー マネージャ] 階層ウィンドウで [役割] を展開し、[Web サーバー (IIS)] をクリックします。
  3. [Web サーバー (IIS)] ペインで、[役割サービス] セクションまでスクロールし、[役割サービスの追加] をクリックします。
  4. 役割サービスの追加ウィザード[役割サービスの選択] ページで、[トレース] を選び、[次へ] をクリックします。
    [トレース] が選択された状態で展開された [役割サービスの選択] ウィンドウのスクリーンショット。
  5. [インストール オプションの確認] ページで、[インストール] をクリックします。
  6. [結果] ページで、 [閉じる]をクリックします。

Windows Vista または Windows 7

  1. タスク バーで、[スタート][コントロール パネル] の順にクリックします。
  2. [コントロール パネル][プログラムと機能] をクリックし、次に [Windows の機能の有効化または無効化] をクリックします。
  3. [インターネット インフォメーション サービス][World Wide Web サービス][正常性と診断] の順に展開します。
  4. [トレース] を選んで [OK] をクリックします。
    [トレース] が選択された状態で展開された [インターネット インフォメーション サービス] ウィンドウのスクリーンショット。

操作方法

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

  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. [操作] ウィンドウで、[失敗した要求のトレース] を選択します。
    アプリケーション アイコンが表示された I I S Manager コンソールのスクリーンショット。

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

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

  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. ホーム ウィンドウの [失敗した要求トレースの規則] をダブルクリックします。
    アプリケーション アイコンが表示された I I S Manager コンソールのスクリーンショット。

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

  5. [失敗した要求トレース規則の追加] ウィザードの [トレースするコンテンツの指定] ページで、トレースするコンテンツ タイプを選択し、[次へ] を選択します。
    [すべてのコンテンツ] が選択された [失敗した要求トレースルールの追加] ウィザードのスクリーンショット。

  6. [トレース条件の定義] ページでトレースする条件を選択し、[次へ] を選択します。 トレース条件には、状態コードの任意の組み合わせ、要求に費やされる時間の上限、またはイベントの重大度を含めることができます。 すべての条件を指定すると、最初に満たされた条件によって、失敗した要求トレース ログ ファイルが生成されます。
    状態コード ボックスがオンになっている [トレース条件の定義] ページのスクリーンショット。

  7. [トレース プロバイダーの選択] ページで、[プロバイダー] に 1 つ以上のトレース プロバイダーを選択します。
    [トレース プロバイダーの選択] ページのスクリーンショット。[A S P] と [S P Net] がトレース プロバイダーとして選択されています。

  8. [トレース プロバイダーの選択] ページで、[詳細度] に 1 つ以上の詳細レベルを選択します。
    [トレース プロバイダーの選択] ページのスクリーンショット。[プロバイダーの詳細] に [S P] と [S P Net] が選択されています。

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

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

構成

<traceFailedRequests> 要素は、ApplicationHost.config ファイルのサーバー レベルで構成することも、適切な Web.config ファイルのサイト レベル、アプリケーション レベル、または URL レベルで構成することもできます。

属性

なし。

子要素

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

パス定義のコレクションにパスを追加します。
remove 省略可能な要素です。

パス定義コレクションからパスへの参照を削除します。
clear 省略可能な要素です。

パス定義コレクションからパスへのすべての参照を削除します。

構成サンプル

次の構成例では、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()