ログ <log>
概要
<log>
要素は、インターネット インフォメーション サービス (IIS) 7 のいくつかのグローバル ログ オプションを指定します。 たとえば、centralLogFileMode 属性は、サイト レベルのログ、中央の W3C ログ、中央の Binary ログのいずれを有効にするかを指定します。
サイト レベルのログは、サーバー上のサイトごとに別個のログ ファイル ディレクトリを作成します。各フォルダーには、そのサイトのログ ファイルのみが含まれます。 中央のログを使うと、<centralBinaryLogFile>
要素または<centralW3CLogFile>
要素の period 属性で指定された期間、すべてのサイトに対して 1 つのログ ファイルを使用できます。 期間には、毎日、毎週、毎月、毎時、またはファイルの最大サイズを指定できます。
Note
W3C 形式のログ ファイルは、ほとんどのログ解析ユーティリティが処理できるテキスト ベースのファイルです。 Binary ログ ファイルは、Microsoft の Log Parser ユーティリティなどの、その形式でログ ファイルを処理できるアプリケーションの使用を必要とする独自のストレージ形式を使用します。
互換性
バージョン | メモ |
---|---|
IIS 10.0 | <log> 要素は IIS 10.0 では変更されませんでした。 |
IIS 8.5 | <log> 要素は IIS 8.5 では変更されませんでした。 |
IIS 8.0 | <log> 要素は IIS 8.0 では変更されませんでした。 |
IIS 7.5 | <log> 要素は IIS 7.5 では変更されませんでした。 |
IIS 7.0 | <log> 要素が IIS 7.0 で導入されました。 |
IIS 6.0 | <log> 要素は、次の IIS 6.0 属性を置き換えます。
|
段取り
<log>
要素は IIS 7 の既定のインストールに含まれています。
操作方法
サーバーに対して中央の Binary ログを有効にする方法
次のようにインターネット インフォメーション サービス (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) マネージャー] をダブルクリックします。
[接続] ウィンドウでサーバー名をクリックします。
サーバーの [ホーム] ウィンドウで、[ログ記録] をダブルクリックします。
[ログ記録] ページの [ログ ファイル作成単位] で、ドロップダウン リストから [サーバー] を選択して、[形式] ドロップダウン リストから [Binary] を選びます。
[操作] ウィンドウで [適用] をクリックします。
サーバーに対して中央の W3C ログを有効にする方法
次のようにインターネット インフォメーション サービス (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) マネージャー] をダブルクリックします。
[接続] ウィンドウでサーバー名をクリックします。
サーバーの [ホーム] ウィンドウで、[ログ記録] をダブルクリックします。
[ログ記録] ページの [ログ ファイル作成単位] で、ドロップダウン リストから [サーバー] を選択して、[形式] ドロップダウン リストから [W3C] を選びます。
[操作] ペインで [適用] をクリックします。
構成
属性
属性 | 説明 | ||||||||
---|---|---|---|---|---|---|---|---|---|
centralLogFileMode |
省略可能な列挙型属性。 サーバーの中央のログ モードを指定します。 centralLogFileMode 属性には、次のいずれかの値を指定できます。 既定値は、 Site です。
|
||||||||
logInUTF8 |
省略可能な Boolean 属性です。 IIS がすべての文字列を Unicode Transmission Format 8 (UTF-8) でログするかどうかを指定します。 この設定は、サーバー全体のすべてのテキストモード ログに適用されます。 既定値は true です。 |
子要素
要素 | 説明 |
---|---|
centralBinaryLogFile |
省略可能な要素です。 サーバー上のすべてのサイトに対して中央の Binary ログ設定を指定します。 |
centralW3CLogFile |
省略可能な要素です。 サーバー上のすべてのサイトに対して中央の W3C ログ設定を指定します。 |
構成サンプル
次の構成サンプルは、IIS がサイト レベルのログを使用することを指定します。
<log centralLogFileMode="Site">
<centralBinaryLogFile enabled="true" directory="%SystemDrive%\inetpub\logs\LogFiles" />
<centralW3CLogFile enabled="true" directory="%SystemDrive%\inetpub\logs\LogFiles" />
</log>
次の構成サンプルは、IIS が中央の Binary ログを使用し、Binary ログ ファイル ロールオーバーを毎日に構成することを指定します。
<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 が中央の Binary ログを使用し、Binary ログ ファイル ロールオーバーを毎日に構成することを指定します。
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
Note
AppCmd.exe を使用してこれらの設定を構成するときは、commit パラメーターを必ず apphost
に設定する必要があります。 これで、ApplicationHost.config ファイルの適切な場所セクションに構成設定がコミットされます。
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
Note
AppCmd.exe を使用してこれらの設定を構成するときは、commit パラメーターを必ず apphost
に設定する必要があります。 これで、ApplicationHost.config ファイルの適切な場所セクションに構成設定がコミットされます。
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()