ODBC ログ <odbcLogging>

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

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

概要

<odbcLogging> 要素はインターネット インフォメーション サービス (IIS) 7.0 の Open Database Connectivity (ODBC) ログを構成します。ODBC ログは、すべての HTTP アクティビティを、テキスト ファイルではなくユーザー定義のデータベースに記録します。

ODBC ログは IIS 7.0 のカスタム ログ モジュールとして実装されるため、IIS 7.0 での ODBC ログの有効化と構成は次の 2 つの別個の操作で行います。

  • <odbcLogging> 要素の ODBC ログ属性を設定します。特に、次の属性を構成する必要があります。
    • dataSource 属性では、tableName 属性によって指定されるテーブルが存在するデータベースの、システム データ ソース名 (DSN) を指定する必要があります。
    • password 属性では、ログ情報をデータベースに書き込む際に IIS 7.0 が使用するデータベース パスワードを指定する必要があります。
    • tableName 属性では、dataSource 属性によって指定されるデータベース内のデータベース テーブルの名前を指定する必要があります。
    • userName 属性では、ログ情報をデータベースに書き込む際に IIS 7.0 が使用するデータベース ユーザー名を指定する必要があります。
  • <logFile> 要素で正しいカスタム ログ属性を設定します。特に、次の属性を構成する必要があります。
    • logFormat 属性は、"Custom" に設定する必要があります。
    • customLogPluginClsid 属性は、"{FF16065B-DE82-11CF-BC0A-00AA006111E0}" に設定する必要があります。

既定では、IIS 7.0 はすべてのアクティビティを W3C 拡張ログ ファイル形式を使用するテキスト ファイルにログ記録しますが、NCSA やネイティブ IIS 形式などその他のテキスト ファイル形式を使用するように既定で IIS を構成できます。これらのテキストベースの形式を使用することの主要な欠点は、アクティビティの解析がより難しく、またログから有効な情報を取得するには通常 Microsoft の LogParser(英語) のようなユーティリティを必要とすることです。また、テキスト ファイルによるデータ解析のパフォーマンスは、通常、データベースを使用した場合よりはるかに低速になります。ただし、テキストベースのログはカーネル モードで実行され、それによってログ要求のパフォーマンスは向上します。

ODBC ログを使用すると、サーバーのアクティビティはデータベースに格納されるため、データを取得する際のパフォーマンスが大幅に向上します。これにより、サーバーのアクティビティのデータ マイニング時に、幅広い種類のデータベース クライアントを使用できる可能性が高まります。ODBC ログを使用することの主要な欠点は、ログのパフォーマンスです。これは、ODBC ログが有効にされると、IIS はカーネルモードのキャッシュを無効にするためです。このため、ODBC ログの実装は、全体的なサーバーのパフォーマンスを低下させる可能性があります。

: ODBC ログのテーブルを作成する際は、IIS 7.0 で提供される "%windir%\System32\inetsrv\logtemp.sql" ファイルを使用できます。ODBC ログの詳細については、Microsoft サポート技術情報 245243 を参照してください。

互換性

  IIS 7.0 IIS 6.0
注意 <odbcLogging> は IIS 7.0 で新たに導入された要素です。 <odbcLogging> 要素の属性は、IIS 6.0 の次のメタベース プロパティに代わるものです。

LogOdbcDataSource
LogOdbcPassword
LogOdbcTableName

LogOdbcUserName

セットアップ

<odbcLogging> 要素は、IIS 7.0 の既定のインストールには含まれていません。インストールするには、次の手順を実行します。

Windows Server 2008

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

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

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

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

    拡大

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

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

Windows Vista

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

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

  3. [Internet Information Services] を展開し、[ODBC ログ] を選択して [OK] をクリックします。

    拡大

方法

IIS 7.0 で ODBC ログを構成するためのユーザー インターフェイスはありません。ODBC ログをプログラムによって構成する方法の例については、このドキュメントの「サンプル コード」セクションを参照してください。

構成

属性

属性 説明
dataSource オプションの string 属性。

ログの記録先のデータベースの、システム データ ソース名 (DSN) を指定します。

既定値は InternetDb です。

password オプションの string 属性。

イベント ログ中にデータベースに情報を記録する際に使用する ODBC データベース パスワードを指定します。既定では、この値は暗号化されます。

既定値は [enc:AesProvider::enc] です。

tableName オプションの string 属性。

イベント ログ中に Windows が情報を記録する ODBC データベース テーブルの名前を指定します。

既定値は InternetLog です。

userName オプションの string 属性。

イベント ログ中にデータベースに情報を記録する際に使用する ODBC データベース ユーザー名を指定します。

既定値は InternetAdmin です。

子要素

なし。

構成サンプル

Default Web Site に対する最初の構成サンプルでは、<odbcLogging> 要素内の属性を構成して、ODBC ログ接続用のシステム DSN、テーブル名、ユーザー名、およびパスワードを指定します。

<location path="Default Web Site">
   <system.webServer>

      <odbcLogging dataSource="InternetDb"
         tableName="InternetLog"
         userName="InternetAdmin"
         password="[enc:AesProvider:Encrypted-Password-Data:enc]" />
   </system.webServer>
</location>

この 2 番目の構成サンプルでは、Default Web Site で ODBC ログを有効にするために <logFile> 要素の正しいカスタム ログ属性を構成します。

<site name="Default Web Site" id="1" serverAutoStart="true">

   <application path="/" applicationPool="DefaultAppPool">
      <virtualDirectory path="/" physicalPath="%SystemDrive%\inetpub\wwwroot" />
   </application>
   <bindings>
      <binding protocol="http" bindingInformation="*:80:" />
   </bindings>

   <logFile logFormat="Custom"
      customLogPluginClsid="{FF16065B-DE82-11CF-BC0A-00AA006111E0}" />
</site>

サンプル コード

次のコード サンプルでは、Default Web Site に対して次の 2 つのオプション セットを構成します。

  • 各サンプルの前半部分では、<odbcLogging> 要素内の属性を構成して、ODBC ログ接続用のシステム DSN、テーブル名、ユーザー名、およびパスワードを指定します。
  • 各サンプルの後半部分では、ODBC ログを有効にするために <logFile> 要素内のカスタム ログ属性を指定します。

AppCmd.exe

appcmd.exe set config "Default Web Site" -section:system.webServer/odbcLogging /dataSource:"InternetDb" /commit:apphost
appcmd.exe set config "Default Web Site" -section:system.webServer/odbcLogging /tableName:"InternetLog" /commit:apphost
appcmd.exe set config "Default Web Site" -section:system.webServer/odbcLogging /userName:"InternetAdmin" /commit:apphost
appcmd.exe set config "Default Web Site" -section:system.webServer/odbcLogging /password:"P@ssw0rd" /commit:apphost

appcmd.exe set sites "Default Web Site" -logFile.logFormat:"Custom" /commit:apphost
appcmd.exe set sites "Default Web Site" -logFile.customLogPluginClsid:"{FF16065B-DE82-11CF-BC0A-00AA006111E0}" /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 odbcLoggingSection = config.GetSection("system.webServer/odbcLogging", "Default Web Site");
         odbcLoggingSection["dataSource"] = @"InternetDb";
         odbcLoggingSection["tableName"] = @"InternetLog";
         odbcLoggingSection["userName"] = @"InternetAdmin";
         odbcLoggingSection["password"] = @"P@ssw0rd";

         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 logFileElement = siteElement.GetChildElement("logFile");
         logFileElement["customLogPluginClsid"] = @"{FF16065B-DE82-11CF-BC0A-00AA006111E0}";
         logFileElement["logFormat"] = @"Custom";

         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 odbcLoggingSection As ConfigurationSection = config.GetSection("system.webServer/odbcLogging", "Default Web Site")
      odbcLoggingSection("dataSource") = "InternetDb"
      odbcLoggingSection("tableName") = "InternetLog"
      odbcLoggingSection("userName") = "InternetAdmin"
      odbcLoggingSection("password") = "P@ssw0rd"

      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 logFileElement As ConfigurationElement = siteElement.GetChildElement("logFile")
      logFileElement("customLogPluginClsid") = "{FF16065B-DE82-11CF-BC0A-00AA006111E0}"
      logFileElement("logFormat") = "Custom"

      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 odbcLoggingSection = adminManager.GetAdminSection("system.webServer/odbcLogging", "MACHINE/WEBROOT/APPHOST/Default Web Site");
odbcLoggingSection.Properties.Item("dataSource").Value = "InternetDb";
odbcLoggingSection.Properties.Item("tableName").Value = "InternetLog";
odbcLoggingSection.Properties.Item("userName").Value = "InternetAdmin";
odbcLoggingSection.Properties.Item("password").Value = "P@ssw0rd";

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 logFileElement = siteElement.ChildElements.Item("logFile");
logFileElement.Properties.Item("customLogPluginClsid").Value = "{FF16065B-DE82-11CF-BC0A-00AA006111E0}";
logFileElement.Properties.Item("logFormat").Value = "Custom";

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 odbcLoggingSection = adminManager.GetAdminSection("system.webServer/odbcLogging", "MACHINE/WEBROOT/APPHOST/Default Web Site")
odbcLoggingSection.Properties.Item("dataSource").Value = "InternetDb"
odbcLoggingSection.Properties.Item("tableName").Value = "InternetLog"
odbcLoggingSection.Properties.Item("userName").Value = "InternetAdmin"
odbcLoggingSection.Properties.Item("password").Value = "P@ssw0rd"

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 logFileElement = siteElement.ChildElements.Item("logFile")
logFileElement.Properties.Item("customLogPluginClsid").Value = "{FF16065B-DE82-11CF-BC0A-00AA006111E0}"
logFileElement.Properties.Item("logFormat").Value = "Custom"

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