Central W3C Log File <centralW3CLogFile>
Overview
The <centralW3CLogFile>
element specifies the central W3C log settings for all sites on a server.
Note
You need to set the centralLogFileMode attribute of the parent <log>
element to CentralW3C in order for the attributes on the <centralW3CLogFile>
element to have effect. If the centralLogFileMode attribute of the <log>
element is set to CentralBinary 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.
Compatibility
Version | Notes |
---|---|
IIS 10.0 | The <centralW3CLogFile> element was not modified in IIS 10.0. |
IIS 8.5 | The <centralW3CLogFile> element was not modified in IIS 8.5. |
IIS 8.0 | The <centralW3CLogFile> element was not modified in IIS 8.0. |
IIS 7.5 | The <centralW3CLogFile> element was not modified in IIS 7.5. |
IIS 7.0 | The <centralW3CLogFile> element of the <log> element was introduced in IIS 7.0. |
IIS 6.0 | The <log> element replaces the IIS 6.0 CentralW3CLoggingEnabled flag. |
Setup
The <centralW3CLogFile>
element of the <log>
element is included in the default installation of IIS 7.
How To
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.
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 | ||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
directory |
Optional string attribute. Specifies the directory where log entries are written. The default value is %SystemDrive%\inetpub\logs\LogFiles . |
||||||||||||||||||||||||||||||||||||||||||||||
enabled |
Optional Boolean attribute. Specifies whether central W3C logging is enabled. The default value is true . |
||||||||||||||||||||||||||||||||||||||||||||||
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 . |
||||||||||||||||||||||||||||||||||||||||||||||
logExtFileFlags |
Optional flags attribute. Specifies which fields to log. The logExtFileFlags attribute can have one of the following values or a list of these values. The default is a list of these values: Date , Time , ClientIP , UserName , SiteName , ServerIP , Method , UriStem , UriQuery , HttpStatus , TimeTaken ,Win32Status , ServerPort , UserAgent , HttpSubStatus .
|
||||||||||||||||||||||||||||||||||||||||||||||
period |
Optional enum attribute. Specifies how frequently the current log file is closed and a new log file is started. The period attribute can be one of the following possible values. The default is Daily .
|
||||||||||||||||||||||||||||||||||||||||||||||
truncateSize |
Optional int64 attribute. Specifies the size, in bytes, at which the log file contents will 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 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 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()