Default Log File Settings for Web Sites <logFile>
The <logFile>
element of the <siteDefaults>
element contains attributes that allow you to configure default logging for a site on IIS 7 and later.
For example, you can enable or disable logging, configure the format of the IIS log file, specify the categories of information to store in the log file, and change the directory where the log file is stored. You can also use the <logFile>
element to control how often IIS creates a new log file based either on log file size or time interval and the maximum size (in bytes) that a log file can become.
By default, IIS 7 and later uses the World Wide Web Consortium (W3C) log file format. You can change this setting by modifying the logFormat attribute to IIS, NCSA, or Custom.
Note
ODBC logging is implemented as a custom logging module in IIS 7 and later. As a result, enabling and configuring ODBC logging in IIS 7 and later consists of two separate actions:
- Setting the ODBC logging attributes in the
<odbcLogging>
element. These attributes specify the System Data Source Name (DSN), table name, user name, and password for the ODBC connection. - Setting the correct custom logging attributes in
<logFile>
element. These attributes must set the log file format to "Custom" and the custom log plug-in class ID to "{FF16065B-DE82-11CF-BC0A-00AA006111E0}".
For more information about ODBC logging, see the <odbcLogging>
element.
You can define the categories of information that IIS logs by editing the logExtFileFlags attribute. The default values are Date
, Time
, ClientIP
, UserName
, ServerIP
, Method
, UriStem
, UriQuery
, TimeTaken
, HttpStatus
, Win32Status
, ServerPort
, UserAgent
, HttpSubStatus
, and Referer
.
Note
If the <logFile>
element is configured in both the <siteDefaults>
section and in the <site>
section for a specific site, the configuration in the <site>
section is used for that site.
IIS 8.5 enables you to log custom fields in addition to the standard logged set. The log file format must be W3C to add custom fields. For more information, see customFields
.
Version | Notes |
---|---|
IIS 10.0 | The <logFile> element was not modified in IIS 10.0. |
IIS 8.5 | Added the flushByEntrycountW3CLog attribute to specify the number of events to be store in the buffer before they are flushed to the log file. Added the logTargetW3C attribute to specify how logged IIS events are processed. Added the maxLogLineLength attribute to specify the maximum length of a line in a log file. Added the <customFields> child element. |
IIS 8.0 | The logSiteId attribute was added to specify the contents of the -sitename field, and referer flag was added to the default value of the logExtFileFlags attribute. |
IIS 7.5 | The <logFile> element was not modified in IIS 7.5. |
IIS 7.0 | The <logFile> element of the <siteDefaults> element was introduced in IIS 7.0. |
IIS 6.0 | The <logFile> element replaces sections of the logging properties on the IIS 6.0 IIsWebService metabase object. |
The <logFile>
element is included in the default installation of IIS 7 and later.
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 which you want to configure logging.
In the Logging pane, select the log file format in the Format box, and then type the path to the directory where you store the log files in the Directory box or click Browse... to choose the directory in which to store the log files.
If you choose to use the W3C log file format:
Open Internet Information Services (IIS) Manager:
If you are using 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.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.
In the Connections pane, expand the server name.
In the site's home pane, double-click Logging.
In the Logging home page, for Log Event Destination, select Log file only, ETW event only, or Both log file and ETW event.
Open Internet Information Services (IIS) Manager:
If you are using 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.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.
In the Connections pane, select the server, and then double-click Configuration Editor.
In the Configuration Editor, for the Section, expand
system.applicationHost
, and then select sites.Expand siteDefaults, and then expand logFile.
For flushByEntryCountW3Clog, enter the number of events to be stored in the buffer before they are flushed to the log file.
In the Action pane, click Apply.
Open Internet Information Services (IIS) Manager:
If you are using 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.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.
In the Connections pane, expand the server, and then double-click Configuration Editor.
In the Configuration Editor, for the Section, expand
system.applicationHost
, and then select sites.Expand siteDefaults, and then expand logFile.
For maxLogLineLength, enter the maximum number of bytes in a single line of a log file.
In the Action pane, click Apply.
Attribute | Description | ||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
customLogPluginClsid |
Optional string attribute. Specifies the COM object class ID (CLSID) or IDs, in order of precedence, for custom modules. |
||||||||||||||||||||||||||||||||||||||||||||||
directory |
Optional string attribute. Specifies the logging directory, where the log file and logging-related support files are stored. The default value is %SystemDrive%\inetpub\logs\LogFiles . |
||||||||||||||||||||||||||||||||||||||||||||||
enabled |
Optional Boolean attribute. Specifies whether logging is enabled (true) or disabled (false) for a site. Note: ASP and ODBC errors are not logged in the IIS log files. The default value is true . |
||||||||||||||||||||||||||||||||||||||||||||||
flushByEntryCountW3CLog |
Optional uint attribute. Specifies the number of events to be stored in the buffer before they are flushed to the log file. A lower number will cause events to be flushed more quickly, at the cost of performance as a result of a greater number of disk operations. Reduce this value for more real-time troubleshooting, increase it for performance. A value of 0 specifies that the flush will occur at the default maximum of 64k.The default value is 0 . |
||||||||||||||||||||||||||||||||||||||||||||||
localTimeRollover |
Optional Boolean attribute. Specifies whether a new log file is created based on local time or Coordinated Universal Time (UTC), which was previously called Greenwich Mean Time (GMT). When false, a new log file is created based on UTC. Note: Regardless of the setting, the time stamp for each W3C Extended Logging log record is UTC-based. The default value is false . |
||||||||||||||||||||||||||||||||||||||||||||||
logExtFileFlags |
Optional flags attribute. Specifies the categories of information that are written to either the log file (when you use W3C Extended log file format) or to the ODBC data source during logging events for a site. The logExtFileFlags attribute can be one or more of the following values. If you specify more than one value, separate them with a comma (,). The default values are Date , Time , ClientIP , UserName , ServerIP , Method , UriStem , UriQuery , TimeTaken , HttpStatus , Win32Status , ServerPort , UserAgent , HttpSubStatus , Referer .
|
||||||||||||||||||||||||||||||||||||||||||||||
logFormat |
Optional enum attribute. Specifies the log file format. The logFormat attribute can be one of the following values. The default value is W3C .
|
||||||||||||||||||||||||||||||||||||||||||||||
logSiteId |
Optional Boolean attribute. Specifies that the s-sitename field will contain either the site name (false) or the site ID (true). If the One log file per property is set to Site (the out-of-box default], then you won't get s-sitename column in the log file by default, because the log file name property will contain the site ID instead. If the One log file per property is set to Server , the-s-sitename column will be included in the log file by default.The default value is True , meaning that the s-sitename field contains the site ID. To log the site name instead, set logSiteID to False . |
||||||||||||||||||||||||||||||||||||||||||||||
logTargetW3C |
Optional Flags attribute. Specifies whether IIS will use Event Tracing for Windows (ETW) and/or file logging for processing logged IIS events. ETW provides real-time logging and use of an ETW provider and standard querying mechanisms. File logging stores event data in text files that you can parse to access logging data. When IIS uses log files, HTTP.sys logs data directly into text log files after the transaction has completed. When using ETW, HTTP.sys sends data into ETW using the iislogging provider, and the LOGSVC service manages the log data, including querying ETW for data, gathering data directly from worker processes, and sending the data to a log file. The logTargetW3C attribute can have the following possible values. The default value is File . If both File and ETW are listed for logTargetW3C for the server's log file defaults in applicationHost.config, that is equivalent to selecting Both log file and ETW event in the server's Logging pane in the IIS Manager.
|
||||||||||||||||||||||||||||||||||||||||||||||
maxLogLineLength |
Optional uint attribute. Specifies the maximum length of a line in a log file. This enables you to limit the amount of data accumulated by logging, and save on disk space, especially when you add custom logging fields. The range is 2 to 65,536. The default value is 65536 . |
||||||||||||||||||||||||||||||||||||||||||||||
period |
Optional enum attribute. Specifies how often IIS creates a new log file. The period attribute can be one of the following possible values. The default value is Daily .
|
||||||||||||||||||||||||||||||||||||||||||||||
truncateSize |
Optional int64 attribute. Specifies the maximum size of the log file (in bytes) after which to create a new log file. This value is only applicable when MaxSize is chosen for the period attribute. The minimum file size is 1,048,576 bytes. If this attribute is set to a value less than 1,048,576 bytes, the default value is implicitly assumed as 1,048,576 bytes. The default value is 20971520 . |
Element | Description |
---|---|
customFields |
Optional element. Specifies the configuration settings for default custom fields in a W3C log. |
The following configuration sample specifies default logFile
options.
<system.applicationHost>
<sites>
<siteDefaults>
<logFile logFormat="W3C"
directory="%SystemDrive%\inetpub\logs\LogFiles"
enabled="true">
<customFields>
<clear/>
<add logFieldName="ContosoField" sourceName="ContosoSource"
sourceType="ServerVariable" />
</customFields>
</logFile>
</siteDefaults>
</sites>
</system.applicationHost>
The following code samples configure the default logFile
options for IIS 7.
appcmd.exe set config -section:system.applicationHost/sites /siteDefaults.logFile.enabled:"True" /commit:apphost
appcmd.exe set config -section:system.applicationHost/sites /siteDefaults.logFile.logFormat:"W3C" /commit:apphost
appcmd.exe set config -section:system.applicationHost/sites /siteDefaults.logFile.directory:"%SystemDrive%\inetpub\logs\LogFiles" /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.
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 sitesSection = config.GetSection("system.applicationHost/sites");
ConfigurationElement siteDefaultsElement = sitesSection.GetChildElement("siteDefaults");
ConfigurationElement logFileElement = siteDefaultsElement.GetChildElement("logFile");
logFileElement["logFormat"] = @"W3C";
logFileElement["directory"] = @"%SystemDrive%\inetpub\logs\LogFiles";
logFileElement["enabled"] = true;
serverManager.CommitChanges();
}
}
}
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 sitesSection As ConfigurationSection = config.GetSection("system.applicationHost/sites")
Dim siteDefaultsElement As ConfigurationElement = sitesSection.GetChildElement("siteDefaults")
Dim logFileElement As ConfigurationElement = siteDefaultsElement.GetChildElement("logFile")
logFileElement("logFormat") = "W3C"
logFileElement("directory") = "%SystemDrive%\inetpub\logs\LogFiles"
logFileElement("enabled") = True
serverManager.CommitChanges()
End Sub
End Module
var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST");
var siteDefaultsElement = sitesSection.ChildElements.Item("siteDefaults");
var logFileElement = siteDefaultsElement.ChildElements.Item("logFile");
logFileElement.Properties.Item("logFormat").Value = "W3C";
logFileElement.Properties.Item("directory").Value = "%SystemDrive%\\inetpub\\logs\\LogFiles";
logFileElement.Properties.Item("enabled").Value = true;
adminManager.CommitChanges();
Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set sitesSection = adminManager.GetAdminSection("system.applicationHost/sites", "MACHINE/WEBROOT/APPHOST")
Set siteDefaultsElement = sitesSection.ChildElements.Item("siteDefaults")
Set logFileElement = siteDefaultsElement.ChildElements.Item("logFile")
logFileElement.Properties.Item("logFormat").Value = "W3C"
logFileElement.Properties.Item("directory").Value = "%SystemDrive%\inetpub\logs\LogFiles"
logFileElement.Properties.Item("enabled").Value = True
adminManager.CommitChanges()