共用方式為


中央二進位記錄檔 < centralBinaryLogFile>

概觀

元素 <centralBinaryLogFile> 會指定伺服器上所有月臺的中央二進位記錄設定。

注意

您必須將父 <log> 元素的centralLogFileMode屬性設定為CentralBinary,才能讓專案上的 <centralW3CLogFile> 屬性生效。 如果專案的 centralLogFileMode 屬性 <log> 設定為 CentralW3CSite,則會忽略元素上的 <centralW3CLogFile> 屬性。

注意

W3C 格式的記錄檔是以文字為基礎的檔案,大部分的記錄剖析公用程式都可以處理。 二進位記錄檔會使用專屬的儲存格式,需要使用可處理該格式之記錄檔的應用程式,例如 Microsoft 的 LogParser 公用程式。

相容性

版本 備註
IIS 10.0 未在 IIS 10.0 中修改專案 <centralBinaryLogFile>
IIS 8.5 未在 IIS 8.5 中修改專案 <centralBinaryLogFile>
IIS 8.0 未在 IIS 8.0 中修改專案 <centralBinaryLogFile>
IIS 7.5 未在 IIS 7.5 中修改專案 <centralBinaryLogFile>
IIS 7.0 元素 <centralBinaryLogFile><log> 元素是在 IIS 7.0 中引進。
IIS 6.0 元素 <log> 會取代 IIS 6.0 CentralBinaryLoggingEnabled 旗標。

安裝程式

元素 <centralBinaryLogFile><log> 元素包含在 IIS 7 的預設安裝中。

作法

如何啟用伺服器的中央二進位記錄

  1. 開啟 [Internet Information Services (IIS) 管理員

    • 如果您使用 Windows Server 2012 或 Windows Server 2012 R2:

      • 在工作列上,依序按一下 [伺服器管理員]、[工具],然後按一下 [Internet Information Services (IIS) Manager]。
    • 如果您使用 Windows 8 或 Windows 8.1:

      • 按住Windows鍵,按字母X,然後按一下[主控台]。
      • 按一下 [系統管理工具],然後按兩下 [ Internet Information Services (IIS) Manager]。
    • 如果您使用 Windows Server 2008 或 Windows Server 2008 R2:

      • 在工作列上,按一下 [ 開始],指向 [ 系統管理工具],然後按一下 [ Internet Information Services (IIS) 管理員]。
    • 如果您使用 Windows Vista 或 Windows 7:

      • 在工作列上,按一下 [開始],然後按一下[主控台]。
      • 按兩下 [系統管理工具],然後按兩下 [ Internet Information Services] (IIS) Manager
  2. 在 [ 連線] 窗格中,按一下伺服器名稱。

  3. 在伺服器的 [ 首頁] 窗格中,按兩下 [記錄]。
    [I I S Manager] 視窗的螢幕擷取畫面,其中顯示 [伺服器首頁]。[記錄] 圖示會反白顯示。

  4. 在 [記錄] 頁面的[每一個記錄檔] 下,從下拉式清單中選取 [伺服器],然後從 [格式] 下拉式清單中選擇 [二進位]。
    I S Manager 的螢幕擷取畫面,其中顯示 [記錄] 頁面。

  5. 在 [動作] 窗格中按一下 [套用]

組態

屬性

屬性 描述
directory 選擇性字串屬性。

指定寫入記錄專案的目錄。
enabled 選擇性的 Boolean 屬性。

指定是否啟用中央二進位記錄。 此外, centralLogFileMode 必須設定為 CentralBinary ,才能完全啟用中央二進位記錄。

預設值是 false
localTimeRollover 選擇性的 Boolean 屬性。

指定是否根據當地時間或國際標準時間 (UTC) 建立新的記錄檔。 true值表示新的記錄檔是以當地時間為基礎;false表示它是以 UTC 為基礎。

預設值是 false
period 選擇性列舉屬性。

指定應該清除記錄檔內容的頻率。

period 屬性可以是下列其中一個可能的值。

預設值是 Daily
描述
MaxSize 每當記錄檔達到 truncateSize 屬性所指定的大小時,就會清除記錄檔。

數值為 0
Daily 每天清除記錄檔。

數值為 1
Weekly 記錄檔每週會清除一次。

數值為 2
Monthly 記錄檔會一個月清除一次。

數值為 3
Hourly 每小時都會清除記錄檔。

數值為 4
truncateSize 選擇性 int64 屬性。

指定應該截斷記錄檔內容的大小。 當 period 屬性的值是 maxSize時,必須設定這個屬性。 大小必須介於 1048576 (1 MB) 和 4294967295 (4 GB) 之間。

預設值為 20971520 (20 MB) 。

子元素

無。

組態範例

下列設定範例會指定 IIS 會使用中央二進位記錄,並每天設定二進位記錄檔輪替。

<log centralLogFileMode="CentralBinary">
   <centralBinaryLogFile enabled="true" directory="%SystemDrive%\inetpub\logs\LogFiles" period="Daily" />
   <centralW3CLogFile enabled="true" directory="%SystemDrive%\inetpub\logs\LogFiles" />
</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

注意

當您使用 AppCmd.exe 來設定這些設定時,請務必將 認可 參數 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()