The <centralBinaryLogFile> element specifies the central binary log settings for all sites on a server.
Note: You need to set the centralLogFileMode attribute of the parent <log> element to CentralBinary in order for the attributes on the <centralW3CLogFile> element to have effect. If the centralLogFileMode attribute of the <log> element is set to CentralW3C or Site, the attributes on the <centralW3CLogFile> element will be ignored.
Note: Log files in W3C format are text-based files that most log-parsing utilities can process. Binary log files use a proprietary storage format that requires the use of an application that can process log files in that format, such as Microsoft's LogParser utility.
| |
IIS 7.0 |
IIS 6.0 |
| Notes |
The <centralBinaryLogFile> element of the <log> element is new in IIS 7.0. |
The <log> element replaces the IIS 6.0 CentralBinaryLoggingEnabled flag. |
The <centralBinaryLogFile> element of the <log> element is included in the default installation of IIS 7.0.
How to enable central binary logging for a server
- On the taskbar, click Start, point to Administrative Tools, and then click Internet Information Services (IIS) Manager.
- In the Connections pane, click the server name.
- In the server's Home pane, double-click Logging.
- On the Logging page, under One log file per, select Server from the drop-down list, then choose Binary from the Format drop-down list.
- Click Apply in the Actions pane.
Attributes
| Attribute |
Description |
directory |
Optional string attribute.
Specifies the directory where log entries are written. |
enabled |
Optional Boolean attribute.
Specifies whether central binary logging is enabled. Additionally, centralLogFileMode must be set to CentralBinary in order to fully enable central binary logging.
The default value is false. |
localTimeRollover |
Optional Boolean attribute.
Specifies whether a new log file is created based on local time or Coordinated Universal Time (UTC). A value of true means the new log file is based on local time; false means it is based on UTC.
The default value is false. |
period |
Optional enum attribute.
Specifies how frequently the log file contents should be cleared.
The period attribute can be one of the following possible values.
The default value is Daily.
| Value |
Description |
MaxSize |
Log files are cleared whenever the log file reaches the size specified by the truncateSize attribute.
The numeric value is 0. |
Daily |
Log files are cleared every day.
The numeric value is 1. |
Weekly |
Log files are cleared once a week.
The numeric value is 2. |
Monthly |
Log files are cleared once a month.
The numeric value is 3. |
Hourly |
Log files are cleared every hour.
The numeric value is 4. |
|
truncateSize |
Optional int64 attribute.
Specifies the size at which the log file contents should be truncated. This attribute must be set when the value of the period attribute is maxSize. The size must be between 1048576 (1 megabyte) and 4294967295 (4 gigabytes).
The default value is 20971520 (20 megabytes). |
Child Elements
None.
Configuration Sample
The following configuration sample specifies that IIS will use central binary logging, and configures binary log file rotation on a daily basis.
<log centralLogFileMode="CentralBinary">
<centralBinaryLogFile enabled="true" directory="%SystemDrive%\inetpub\logs\LogFiles" period="Daily" />
<centralW3CLogFile enabled="true" directory="%SystemDrive%\inetpub\logs\LogFiles" />
</log>
The following code samples specify that IIS will use central binary logging, and configure binary log file rotation on a daily basis.
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()