サイトの失敗した要求トレース ログ <traceFailedRequestsLogging>

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

※本ページに挿入されている画像をクリックすると、画像全体が別ウィンドウで表示されます。

概要

<site> 要素の <traceFailedRequestsLogging> 要素は、失敗した要求トレース ログ ファイルのディレクトリ、失敗した要求トレース ログ ファイルの最大数、失敗した要求トレースを有効にするかどうかなど、サイトの失敗した要求トレースのオプションを設定します。

: 特定のサイトにおいて <siteDefaults> セクションと <site> セクションの両方で <traceFailedRequestsLogging> 要素が構成されている場合、そのサイトでは <site> セクションの構成が使用されます。

: <traceFailedRequestsLogging> 要素は、失敗した要求トレースのサイトレベルのオプションを指定します。一方、<system.webServer/tracing/traceFailedRequests> 要素は、失敗した要求トレースの規則を指定します。

互換性

  IIS 7.0 IIS 6.0
説明 <site><traceFailedRequestsLogging> は IIS 7.0 で新たに導入された要素です。 なし

セットアップ

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

Windows Server 2008

  1. タスク バーの [スタート] ボタンをクリックし、[管理ツール] をポイントして [サーバー マネージャー] をクリックします。

  2. [サーバー マネージャー] のツリー表示で、[役割] を展開して [Web サーバー (IIS)] をクリックします。

  3. [Web サーバー (IIS)] ウィンドウで、[役割サービス] セクションまでスクロールして [役割サービスの追加] をクリックします。

  4. 役割サービスの追加ウィザードの [役割サービスの選択] ページで、[トレース] を選択して、[次へ] をクリックします。

    拡大

  5. [インストール オプションの確認] ページで [インストール] をクリックします。

  6. [結果] ページで [閉じる] をクリックします。

Windows Vista

  1. タスク バーの [スタート] ボタンをクリックし、[コントロール パネル] をクリックします。

  2. [コントロール パネル][プログラムと機能] をクリックして、[Windows の機能の有効化または無効化] をクリックします。

  3. [Internet Information Services][World Wide Web サービス][健常性と診断] の順に展開します。

  4. [追跡] を選択して、[OK] をクリックします。

    拡大

方法

サイトの失敗した要求トレース設定を構成する方法

  1. タスク バーの [スタート] ボタンをクリックして、[管理ツール] をポイントし、[インターネット インフォメーション サービス (IIS) マネージャー] をクリックします。

  2. [接続] ウィンドウで、対象のサーバー名、[サイト] ノードの順に展開し、対象のサイト名をクリックします。

  3. サイトの [ホーム] ウィンドウで、[操作] ウィンドウにある [失敗した要求トレース] をクリックします。

    拡大

  4. [Web サイトの失敗した要求トレース設定の編集] ダイアログ ボックスで、トレースのオプションを指定して、[OK] をクリックします。

    拡大

構成

属性

属性 説明
customActionsEnabled オプションの Boolean 属性。

失敗した要求トレースでカスタム アクションを有効にするかどうかを指定します。

既定値は false です。
directory オプションの string 属性。

サイトの失敗した要求トレース ログのディレクトリを指定します。

既定値は %SystemDrive%\inetpub\logs\FailedReqLogFiles です。
enabled オプションの Boolean 属性。

サイトの失敗した要求トレース ログを有効にするか (true)、または無効にするか (false) を指定します。

既定値は false です。
maxLogFiles オプションの uint 属性。

サイトで保持する失敗した要求トレース ログ ファイルの最大数を指定します。

既定値は 50 です。
maxLogFileSizeKB オプションの uint 属性。

失敗した要求トレース ログの最大ファイル サイズを KB 単位で指定します。

: 失敗した要求トレース ログがこの値を超えた場合、IIS によって最大ファイル サイズでログが切り捨てられ、トレース イベントに対して LOG_FILE_MAX_SIZE_TRUNCATE が指定されます。

既定値は 512 です。

子要素

なし。

構成サンプル

次の構成サンプルは、失敗した要求トレースのログが有効になっており、履歴として 10 個のログ ファイルが保持される Web サイトを示しています。

<site name="Default Web Site" id="1" serverAutoStart="true">
   <application path="/">
      <virtualDirectory path="/" physicalPath="%SystemDrive%\inetpub\wwwroot" />

   </application>
   <bindings>
      <binding protocol="http" bindingInformation="*:80:" />
   </bindings>
   <traceFailedRequestsLogging enabled="true"
      directory="%SystemDrive%\inetpub\logs\FailedReqLogFiles"
      maxLogFiles="10" />
</site>

サンプル コード

次のコード サンプルは、Default Web Site で失敗した要求のログを有効にする方法、およびログ ディレクトリとログ ファイルの最大数を設定する方法を示しています。

AppCmd.exe

appcmd.exe set config -section:system.applicationHost/sites "/[name='Default Web Site'].traceFailedRequestsLogging.enabled:True" /commit:apphost
appcmd.exe set config -section:system.applicationHost/sites "/[name='Default Web Site'].traceFailedRequestsLogging.maxLogFiles:10" /commit:apphost
appcmd.exe set config -section:system.applicationHost/sites "/[name='Default Web Site'].traceFailedRequestsLogging.directory:%SystemDrive%\inetpub\logs\FailedReqLogFiles" /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 sitesSection = config.GetSection("system.applicationHost/sites");
         ConfigurationElementCollection sitesCollection = sitesSection.GetCollection();

         ConfigurationElement siteElement = FindElement(sitesCollection, "site", "name", @"Default Web Site");
         if (siteElement == null) throw new InvalidOperationException("Element not found!");

         ConfigurationElement traceFailedRequestsLoggingElement = siteElement.GetChildElement("traceFailedRequestsLogging");
         traceFailedRequestsLoggingElement["enabled"] = true;
         traceFailedRequestsLoggingElement["directory"] = @"%SystemDrive%\inetpub\logs\FailedReqLogFiles";
         traceFailedRequestsLoggingElement["maxLogFiles"] = 10;

         serverManager.CommitChanges();
      }
   }

   private static ConfigurationElement FindElement(ConfigurationElementCollection collection, string elementTagName, params string[] keyValues)
   {
      foreach (ConfigurationElement element in collection)
      {
         if (String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase))
         {
            bool matches = true;
            for (int i = 0; i < keyValues.Length; i += 2)
            {
               object o = element.GetAttributeValue(keyValues[i]);
               string value = null;
               if (o != null)
               {
                  value = o.ToString();
               }
               if (!String.Equals(value, keyValues[i + 1], StringComparison.OrdinalIgnoreCase))
               {
                  matches = false;
                  break;
               }
            }
            if (matches)
            {
               return element;
            }
         }
      }
      return null;
   }
}

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 sitesSection As ConfigurationSection = config.GetSection("system.applicationHost/sites")
      Dim sitesCollection As ConfigurationElementCollection = sitesSection.GetCollection

      Dim siteElement As ConfigurationElement = FindElement(sitesCollection, "site", "name", "Default Web Site")
      If (siteElement Is Nothing) Then
         Throw New InvalidOperationException("Element not found!")
      End If

      Dim traceFailedRequestsLoggingElement As ConfigurationElement = siteElement.GetChildElement("traceFailedRequestsLogging")
      traceFailedRequestsLoggingElement("enabled") = True
      traceFailedRequestsLoggingElement("directory") = "%SystemDrive%\inetpub\logs\FailedReqLogFiles"
      traceFailedRequestsLoggingElement("maxLogFiles") = 10

      serverManager.CommitChanges()
   End Sub

   Private Function FindElement(ByVal collection As ConfigurationElementCollection, ByVal elementTagName As String, ByVal ParamArray keyValues() As String) As ConfigurationElement
      For Each element As ConfigurationElement In collection
         If String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase) Then
            Dim matches As Boolean = True
            Dim i As Integer
            For i = 0 To keyValues.Length - 1 Step 2
               Dim o As Object = element.GetAttributeValue(keyValues(i))
               Dim value As String = Nothing
               If (Not (o) Is Nothing) Then
                  value = o.ToString
               End If
               If Not String.Equals(value, keyValues((i + 1)), StringComparison.OrdinalIgnoreCase) Then
                  matches = False
                  Exit For
               End If
            Next
            If matches Then
               Return element
            End If
         End If
      Next
      Return Nothing
   End Function

End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST");
var sitesCollection = sitesSection.Collection;

var siteElementPos = FindElement(sitesCollection, "site", ["name", "Default Web Site"]);
if (siteElementPos == -1) throw "Element not found!";
var siteElement = sitesCollection.Item(siteElementPos);

var traceFailedRequestsLoggingElement = siteElement.ChildElements.Item("traceFailedRequestsLogging");
traceFailedRequestsLoggingElement.Properties.Item("enabled").Value = true;
traceFailedRequestsLoggingElement.Properties.Item("directory").Value = "%SystemDrive%\\inetpub\\logs\\FailedReqLogFiles";
traceFailedRequestsLoggingElement.Properties.Item("maxLogFiles").Value = 10;

adminManager.CommitChanges();

function FindElement(collection, elementTagName, valuesToMatch) {
   for (var i = 0; i < collection.Count; i++) {
      var element = collection.Item(i);
      if (element.Name == elementTagName) {
         var matches = true;
         for (var iVal = 0; iVal < valuesToMatch.length; iVal += 2) {
            var property = element.GetPropertyByName(valuesToMatch[iVal]);
            var value = property.Value;
            if (value != null) {
               value = value.toString();
            }
            if (value != valuesToMatch[iVal + 1]) {
               matches = false;
               break;
            }
         }
         if (matches) {
            return i;
         }
      }
   }
   return -1;
}

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST")
Set sitesCollection = sitesSection.Collection

siteElementPos = FindElement(sitesCollection, "site", Array("name", "Default Web Site"))
If (siteElementPos = -1) Then
   WScript.Echo "Element not found!"
   WScript.Quit
End If
Set siteElement = sitesCollection.Item(siteElementPos)

Set traceFailedRequestsLoggingElement = siteElement.ChildElements.Item("traceFailedRequestsLogging")
traceFailedRequestsLoggingElement.Properties.Item("enabled").Value = True
traceFailedRequestsLoggingElement.Properties.Item("directory").Value = "%SystemDrive%\inetpub\logs\FailedReqLogFiles"
traceFailedRequestsLoggingElement.Properties.Item("maxLogFiles").Value = 10

adminManager.CommitChanges()

Function FindElement(collection, elementTagName, valuesToMatch)
   For i = 0 To CInt(collection.Count) - 1
      Set element = collection.Item(i)
      If element.Name = elementTagName Then
         matches = True
         For iVal = 0 To UBound(valuesToMatch) Step 2
            Set Property = element.GetPropertyByName(valuesToMatch(iVal))
            value = property.Value
            If Not value = Null Then
               value = CStr(value)
            End If
            If Not value = valuesToMatch(iVal + 1) Then
               matches = False
               Exit For
            End If
         Next
         If matches Then
            Exit For
         End If
      End If
   Next
   If matches Then
      FindElement = i
   Else
      FindElement = -1
   End If
End Function