Default Trace Failed Requests Logging for a Site <traceFailedRequestsLogging>
Overview
The <traceFailedRequestsLogging>
element of the <siteDefaults>
element sets the failed request tracing options for all sites, such as the directory for failed request tracing log files, the maximum number of failed request tracing log files, and whether failed request tracing is enabled.
Note
If the <traceFailedRequestsLogging>
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.
Note
The <traceFailedRequestsLogging>
element specifies the global-level options for failed request tracing, but the <system.webServer/tracing/traceFailedRequests
> element specifies failed request tracing rules.
Compatibility
Version | Notes |
---|---|
IIS 10.0 | The <traceFailedRequestsLogging> element was not modified in IIS 10.0. |
IIS 8.5 | The <traceFailedRequestsLogging> element was not modified in IIS 8.5. |
IIS 8.0 | The default value for the maxLogFileSizeKB attribute was increased. |
IIS 7.5 | The <traceFailedRequestsLogging> element was not modified in IIS 7.5. |
IIS 7.0 | The <traceFailedRequestsLogging> element of the <siteDefaults> element was introduced in IIS 7.0. |
IIS 6.0 | N/A |
Setup
After you finish the default installation of IIS 7 and later, you must install the tracing role service to use failed request tracing. After you install the role service, you still must enable failed request tracing at the site level, application level, or directory level.
Windows Server 2012 or Windows Server 2012 R2
- On the taskbar, click Server Manager.
- In Server Manager, click the Manage menu, and then click Add Roles and Features.
- In the Add Roles and Features wizard, click Next. Select the installation type and click Next. Select the destination server and click Next.
- On the Server Roles page, expand Web Server (IIS), expand Web Server, expand Health and Diagnostics, and then select Tracing. Click Next.
. - On the Select features page, click Next.
- On the Confirm installation selections page, click Install.
- On the Results page, click Close.
Windows 8 or Windows 8.1
- On the Start screen, move the pointer all the way to the lower left corner, right-click the Start button, and then click Control Panel.
- In Control Panel, click Programs and Features, and then click Turn Windows features on or off.
- Expand Internet Information Services, expand World Wide Web Services, expand Health and Diagnostics, and then select Tracing.
- Click OK. - Click Close.
Windows Server 2008 or Windows Server 2008 R2
- On the taskbar, click Start, point to Administrative Tools, and then click Server Manager.
- In the Server Manager hierarchy pane, expand Roles, and then click Web Server (IIS).
- In the Web Server (IIS) pane, scroll to the Role Services section, and then click Add Role Services.
- On the Select Role Services page of the Add Role Services Wizard, select Tracing, and then click Next.
- On the Confirm Installation Selections page, click Install.
- On the Results page, click Close.
Windows Vista or Windows 7
- On the taskbar, click Start, and then click Control Panel.
- In Control Panel, click Programs and Features, and then click Turn Windows Features on or off.
- Expand Internet Information Services, then World Wide Web Services, then Health and Diagnostics.
- Select Tracing, and then click OK.
How To
How to configure the site defaults 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, expand the server name, then click the Sites node.
In the server's Sites pane, click Set Web Site Defaults... in the Actions pane.
In the Web Site Defaults dialog box, specify your default options for all Web sites, and then click OK.
Configuration
Attributes
Attribute | Description |
---|---|
customActionsEnabled |
Optional Boolean attribute. Specifies whether custom actions are enabled for failed request tracing. The default value is false . |
directory |
Optional string attribute. Specifies the failed request trace logging directory for a site. The default value is %SystemDrive%\inetpub\logs\FailedReqLogFiles . |
enabled |
Optional Boolean attribute. Specifies whether failed request trace logging is enabled for a site (true) or disabled (false). The default value is false . |
maxLogFiles |
Optional uint attribute. Specifies the maximum number of failed request tracing log files to keep for the site. The default value is 50 . |
maxLogFileSizeKB |
Optional uint attribute. Specifies the maximum file size in kilobytes for failed request tracing logs. Note: If failed request tracing logs exceed this value, IIS will truncate the logs at the maximum file size and specify LOG_FILE_MAX_SIZE_TRUNCATE for the trace event. The default value is 1024 . |
Child Elements
None.
Configuration Sample
The following configuration sample specifies the default traceFailedRequestsLogging
options for IIS 7.
<system.applicationHost>
<sites>
<siteDefaults>
<traceFailedRequestsLogging enabled="true"
directory="%SystemDrive%\inetpub\logs\FailedReqLogFiles"
maxLogFiles="20" />
</siteDefaults>
</sites>
</system.applicationHost>
Sample Code
The following code samples configure the default traceFailedRequestsLogging
options for IIS 7.
AppCmd.exe
appcmd.exe set config -section:system.applicationHost/sites /siteDefaults.traceFailedRequestsLogging.enabled:"True" /commit:apphost
appcmd.exe set config -section:system.applicationHost/sites /siteDefaults.traceFailedRequestsLogging.directory:"%SystemDrive%\inetpub\logs\FailedReqLogFiles" /commit:apphost
appcmd.exe set config -section:system.applicationHost/sites /siteDefaults.traceFailedRequestsLogging.maxLogFiles:"20" /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 sitesSection = config.GetSection("system.applicationHost/sites");
ConfigurationElement siteDefaultsElement = sitesSection.GetChildElement("siteDefaults");
ConfigurationElement traceFailedRequestsLoggingElement = siteDefaultsElement.GetChildElement("traceFailedRequestsLogging");
traceFailedRequestsLoggingElement["enabled"] = true;
traceFailedRequestsLoggingElement["directory"] = @"%SystemDrive%\inetpub\logs\FailedReqLogFiles";
traceFailedRequestsLoggingElement["maxLogFiles"] = 20;
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 sitesSection As ConfigurationSection = config.GetSection("system.applicationHost/sites")
Dim siteDefaultsElement As ConfigurationElement = sitesSection.GetChildElement("siteDefaults")
Dim traceFailedRequestsLoggingElement As ConfigurationElement = siteDefaultsElement.GetChildElement("traceFailedRequestsLogging")
traceFailedRequestsLoggingElement("enabled") = True
traceFailedRequestsLoggingElement("directory") = "%SystemDrive%\inetpub\logs\FailedReqLogFiles"
traceFailedRequestsLoggingElement("maxLogFiles") = 20
serverManager.CommitChanges()
End Sub
End Module
JavaScript
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 traceFailedRequestsLoggingElement = siteDefaultsElement.ChildElements.Item("traceFailedRequestsLogging");
traceFailedRequestsLoggingElement.Properties.Item("enabled").Value = true;
traceFailedRequestsLoggingElement.Properties.Item("directory").Value = "%SystemDrive%\\inetpub\\logs\\FailedReqLogFiles";
traceFailedRequestsLoggingElement.Properties.Item("maxLogFiles").Value = 20;
adminManager.CommitChanges();
VBScript
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 traceFailedRequestsLoggingElement = siteDefaultsElement.ChildElements.Item("traceFailedRequestsLogging")
traceFailedRequestsLoggingElement.Properties.Item("enabled").Value = True
traceFailedRequestsLoggingElement.Properties.Item("directory").Value = "%SystemDrive%\inetpub\logs\FailedReqLogFiles"
traceFailedRequestsLoggingElement.Properties.Item("maxLogFiles").Value = 20
adminManager.CommitChanges()