Log <log>
Overview
The <log>
element specifies several global logging options for Internet Information Services (IIS) 7. For example, the centralLogFileMode attribute specifies whether site-level logging, central W3C logging, or central binary logging is enabled.
Site-level logging creates individual log file directories for each site on your server, where each folder contains only the log files for that site. Central logging enables the use of a single log file for all sites for the time period specified by the period attribute for the <centralBinaryLogFile>
or <centralW3CLogFile>
element. The time period can be daily, weekly, monthly, hourly, or a maximum file size.
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.
Compatibility
Version | Notes |
---|---|
IIS 10.0 | The <log> element was not modified in IIS 10.0. |
IIS 8.5 | The <log> element was not modified in IIS 8.5. |
IIS 8.0 | The <log> element was not modified in IIS 8.0. |
IIS 7.5 | The <log> element was not modified in IIS 7.5. |
IIS 7.0 | The <log> element was introduced in IIS 7.0. |
IIS 6.0 | The <log> element replaces the following IIS 6.0 attributes:
|
Setup
The <log>
element is included in the default installation of IIS 7.
How To
How to enable central binary logging for a server
Open Internet Information Services (IIS) Manager:
If you are using Windows Server 2012 or Windows Server 2012 R2:
- On the taskbar, click Server Manager, click Tools, and then click Internet Information Services (IIS) Manager.
If you are using Windows 8 or Windows 8.1:
- Hold down the Windows key, press the letter X, and then click Control Panel.
- Click Administrative Tools, and then double-click Internet Information Services (IIS) Manager.
If you are using Windows Server 2008 or Windows Server 2008 R2:
- On the taskbar, click Start, point to Administrative Tools, and then click Internet Information Services (IIS) Manager.
If you are using Windows Vista or Windows 7:
- On the taskbar, click Start, and then click Control Panel.
- Double-click Administrative Tools, and then double-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.
How to enable central W3C logging for a server
Open Internet Information Services (IIS) Manager:
If you are using Windows Server 2012 or Windows Server 2012 R2:
- On the taskbar, click Server Manager, click Tools, and then click Internet Information Services (IIS) Manager.
If you are using Windows 8 or Windows 8.1:
- Hold down the Windows key, press the letter X, and then click Control Panel.
- Click Administrative Tools, and then double-click Internet Information Services (IIS) Manager.
If you are using Windows Server 2008 or Windows Server 2008 R2:
- On the taskbar, click Start, point to Administrative Tools, and then click Internet Information Services (IIS) Manager.
If you are using Windows Vista or Windows 7:
- On the taskbar, click Start, and then click Control Panel.
- Double-click Administrative Tools, and then double-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 W3C from the Format drop-down list.
Click Apply in the Actions pane.
Configuration
Attributes
Attribute | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|
centralLogFileMode |
Optional enum attribute. Specifies the central logging mode for the server. The centralLogFileMode attribute can have one of the following possible values. The default is Site .
|
||||||||
logInUTF8 |
Optional Boolean attribute. Specifies whether IIS should log all strings in UCS Transformation Format 8 (UTF-8). This setting applies server-wide to all text-mode logging. The default value is true . |
Child Elements
Element | Description |
---|---|
centralBinaryLogFile |
Optional element. Specifies the central binary log settings for all sites on a server. |
centralW3CLogFile |
Optional element. Specifies the central W3C log settings for all sites on a server. |
Configuration Sample
The following configuration sample specifies that IIS will use site-level logging.
<log centralLogFileMode="Site">
<centralBinaryLogFile enabled="true" directory="%SystemDrive%\inetpub\logs\LogFiles" />
<centralW3CLogFile enabled="true" directory="%SystemDrive%\inetpub\logs\LogFiles" />
</log>
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 configuration sample specifies that IIS will use central W3C logging, and configures W3C log file rotation on a daily basis.
<log centralLogFileMode="CentralW3C">
<centralBinaryLogFile enabled="true" directory="%SystemDrive%\inetpub\logs\LogFiles" />
<centralW3CLogFile enabled="true" directory="%SystemDrive%\inetpub\logs\LogFiles" period="Daily" />
</log>
Sample Code
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
Note
You must be sure to set the commit parameter to apphost
when you use AppCmd.exe to configure these settings. This commits the configuration settings to the appropriate location section in the ApplicationHost.config file.
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()
The following code samples specify that IIS will use central W3C logging, and configure W3C log file rotation on a daily basis.
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
You must be sure to set the commit parameter to apphost
when you use AppCmd.exe to configure these settings. This commits the configuration settings to the appropriate location section in the ApplicationHost.config file.
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()