ログ <log>

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

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

概要

<log> 要素は、インターネット インフォメーション サービス (IIS) 7.0 のいくつかのグローバル ログ オプションを指定します。たとえば、centralLogFileMode 属性はサイトレベルのログ、W3C 集中ログ、またはバイナリ集中ログのどれが有効かを指定します。

サイトレベルのログでは、サーバー上の各サイトに対して個別のログ ファイル ディレクトリが作成され、各フォルダーにはそのサイトのログ ファイルのみが含まれます。集中ログでは、<centralBinaryLogFile> または <centralW3CLogFile> 要素の period 属性で指定された期間に対して、すべてのサイトに 1 つのログ ファイルを使用できます。期間は毎日、毎週、毎月、毎時、または最大ファイル サイズです。

: W3C 形式のログ ファイルは、ほとんどのログ解析ユーティリティで処理できるテキストベース ファイルです。バイナリ ログ ファイルは独自の保存形式を使用しており、Microsoft の LogParser(英語) ユーティリティなど、その形式のログ ファイルを処理できるアプリケーションが必要です。

互換性

  IIS 7.0 IIS 6.0
注意 <log> は IIS 7.0 で新たに導入された要素です。 <log> 要素は、IIS 6.0 の次の属性に代わるものです。

CentralBinaryLoggingEnabled
CentralW3CLoggingEnabled
LogInUTF8

セットアップ

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

方法

サーバーでバイナリ集中ログを有効にする方法

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

  2. [接続] ウィンドウでサーバー名をクリックします。

  3. サーバーの [ホーム] ウィンドウで [ログ記録] をダブルクリックします。

    拡大

  4. [ログ記録] ページの [ログ ファイル作成単位] で、ドロップダウン リストから [サーバー] を選択し、[形式] ドロップダウン リストから [バイナリ] を選択します。

    拡大

  5. [操作] ウィンドウで [適用] をクリックします。

サーバーで W3C 集中ログを有効にする方法

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

  2. [接続] ウィンドウでサーバー名をクリックします。

  3. サーバーの [ホーム] ウィンドウで [ログ記録] をダブルクリックします。

    拡大

  4. [ログ記録] ページの [ログ ファイル作成単位] で、ドロップダウン リストから [サーバー] を選択し、[形式] ドロップダウン リストから [W3C] を選択します。

    拡大

  5. [操作] ウィンドウで [適用] をクリックします。

構成

属性

属性 説明
centralLogFileMode オプションの enum 属性。

サーバーの集中ログ モードを指定します。

centralLogFileMode 属性には、次のいずれかの値を指定できます。既定値は Site です。

---------------------------------------------------------------------------------------------------------

値: Site

説明:

  • 集中ログの代わりにサイトのログ記録を使用するよう、すべてのサイトを構成します。これは既定の設定です。
  • 数値は 0 です。

値: CentralBinary

説明:

  • Web サーバー上のすべての Web サイトに対して 1 つのログ ファイルを作成します。ログ ファイル内のデータは、カスタマイズできないバイナリベースのフォーマットされていないデータです。
  • 数値は 1 です。

値: CentralW3C

説明:

  • Web サーバー上のすべてのサイトに対する要求を、テキストベースのカスタマイズ可能な ASCII 形式で 1 つの集中ログ ファイルに記録します。
  • 数値は 2 です。
logInUTF8 オプションの Boolean 属性。

IIS ですべての文字列を UTF-8 (UCS Transformation Format 8) でログに記録するかどうかを指定します。この設定は、サーバー全体ですべてのテキストモードのログに適用されます。

既定値は true です。

子要素

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

サーバー上のすべてのサイトのバイナリ集中ログ設定を指定します。
centralW3CLogFile オプションの要素。

サーバー上のすべてのサイトの W3C 集中ログ設定を指定します。

構成サンプル

次の構成サンプルでは、IIS でサイトレベルのログを使用するように指定します。

<log centralLogFileMode="Site">
   <centralBinaryLogFile enabled="true" directory="%SystemDrive%\inetpub\logs\LogFiles" />
   <centralW3CLogFile enabled="true" directory="%SystemDrive%\inetpub\logs\LogFiles" />
</log>

次の構成サンプルでは、IIS でバイナリ集中ログを使用するように指定し、バイナリ ログ ファイルのローテーションを日次で構成しています。

<log centralLogFileMode="CentralBinary">
   <centralBinaryLogFile enabled="true" directory="%SystemDrive%\inetpub\logs\LogFiles" period="Daily" />
   <centralW3CLogFile enabled="true" directory="%SystemDrive%\inetpub\logs\LogFiles" />
</log>

次の構成サンプルでは、IIS で W3C 集中ログを使用するように指定し、W3C ログ ファイルのローテーションを日次で構成しています。

<log centralLogFileMode="CentralW3C">
   <centralBinaryLogFile enabled="true" directory="%SystemDrive%\inetpub\logs\LogFiles" />
   <centralW3CLogFile enabled="true" directory="%SystemDrive%\inetpub\logs\LogFiles" period="Daily" />
</log>

サンプル コード

次のコード サンプルでは、IIS でバイナリ集中ログを使用するように指定し、バイナリ ログ ファイルのローテーションを日次で構成しています。

AppCmd.exe

appcmd.exe set config -section:system.applicationHost/log /centralLogFileMode:"CentralBinary" /commit:apphost

appcmd.exe set config -section:system.applicationHost/log /centralBinaryLogFile.period:"Daily" /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 logSection = config.GetSection("system.applicationHost/log");
         logSection["centralLogFileMode"] = @"CentralBinary";
         ConfigurationElement centralBinaryLogFileElement = logSection.GetChildElement("centralBinaryLogFile");
         centralBinaryLogFileElement["period"] = @"Daily";

         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 logSection As ConfigurationSection = config.GetSection("system.applicationHost/log")
      logSection("centralLogFileMode") = "CentralBinary"
      Dim centralBinaryLogFileElement As ConfigurationElement = logSection.GetChildElement("centralBinaryLogFile")
      centralBinaryLogFileElement("period") = "Daily"

      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";

var logSection = adminManager.GetAdminSection("system.applicationHost/log", "MACHINE/WEBROOT/APPHOST");
logSection.Properties.Item("centralLogFileMode").Value = "CentralBinary";
var centralBinaryLogFileElement = logSection.ChildElements.Item("centralBinaryLogFile");
centralBinaryLogFileElement.Properties.Item("period").Value = "Daily";

adminManager.CommitChanges();

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"

Set logSection = adminManager.GetAdminSection("system.applicationHost/log", "MACHINE/WEBROOT/APPHOST")
logSection.Properties.Item("centralLogFileMode").Value = "CentralBinary"
Set centralBinaryLogFileElement = logSection.ChildElements.Item("centralBinaryLogFile")
centralBinaryLogFileElement.Properties.Item("period").Value = "Daily"

adminManager.CommitChanges()

次のコード サンプルでは、IIS で W3C 集中ログを使用するように指定し、W3C ログ ファイルのローテーションを日次で構成しています。

AppCmd.exe

appcmd.exe set config -section:system.applicationHost/log /centralLogFileMode:"CentralW3C" /commit:apphost

appcmd.exe set config -section:system.applicationHost/log /centralW3CLogFile.period:"Daily" /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 logSection = config.GetSection("system.applicationHost/log");
         logSection["centralLogFileMode"] = @"CentralW3C";
         ConfigurationElement centralW3CLogFileElement = logSection.GetChildElement("centralW3CLogFile");
         centralW3CLogFileElement["period"] = @"Daily";

         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 logSection As ConfigurationSection = config.GetSection("system.applicationHost/log")
      logSection("centralLogFileMode") = "CentralW3C"
      Dim centralW3CLogFileElement As ConfigurationElement = logSection.GetChildElement("centralW3CLogFile")
      centralW3CLogFileElement("period") = "Daily"

      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";

var logSection = adminManager.GetAdminSection("system.applicationHost/log", "MACHINE/WEBROOT/APPHOST");
logSection.Properties.Item("centralLogFileMode").Value = "CentralW3C";
var centralW3CLogFileElement = logSection.ChildElements.Item("centralW3CLogFile");
centralW3CLogFileElement.Properties.Item("period").Value = "Daily";

adminManager.CommitChanges();

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"

Set logSection = adminManager.GetAdminSection("system.applicationHost/log", "MACHINE/WEBROOT/APPHOST")
logSection.Properties.Item("centralLogFileMode").Value = "CentralW3C"
Set centralW3CLogFileElement = logSection.ChildElements.Item("centralW3CLogFile")
centralW3CLogFileElement.Properties.Item("period").Value = "Daily"

adminManager.CommitChanges()