您的位置:首页 > 产品设计 > UI/UE

Trace Failed Requests <traceFailedRequests>

2015-12-02 02:42 501 查看
https://www.iis.net/configreference/system.webserver/tracing/tracefailedrequests

Overview

The
<traceFailedRequests>
element
allows you to configure failed request tracing for a Web site, application, or directory. This element can contain a collection of
<add>
elements
that define tracing rules, each of which specifies the extension of the request URL to which the rule applies, the trace providers and areas to enable, and the conditions that cause this rule to log the events.


Compatibility

VersionNotes
IIS 8.5The
<traceFailedRequests>
element
was not modified in IIS 8.5.
IIS 8.0The
<traceFailedRequests>
element
was not modified in IIS 8.0.
IIS 7.5The
<traceFailedRequests>
element
was not modified in IIS 7.5.
IIS 7.0The
<traceFailedRequests>
element
was introduced in IIS 7.0.
IIS 6.0N/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 clickControl
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 ENABLE TRACING

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,
select the server connection, site, application, or directory for which you want to configure failed request tracing.

In the Actions pane,
click Failed
Request Tracing...





In the Edit
Web Site Failed Request Tracing Settings dialog box, select the Enable check
box to enable tracing, leave the default value or type a new directory where you want to store failed request log files in the Directory box,
type the number of failed request trace files you want to store in the Maximum
number of trace files box, and then click OK.






HOW TO CONFIGURE FAILURE DEFINITIONS

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,
go to the connection, site, application, or directory for which you want to configure failed request tracing.

In the Home pane,
double-click Failed
Request Tracing Rules.





In the Actions pane,
click Add...

On the Specify
Content to Trace page of the Add
Failed Request Tracing Rule Wizard, select the content type you want to trace, and then click Next.





On the Define
Trace Conditions page, select the conditions you want to trace, and then click Next.
Trace conditions can include any combination of status codes, a time limit that a request should take, or the event severity. If you specify all conditions, the first condition that is met generates the failed request trace log file.





On the Select
Trace Providers page, select one or more of the trace providers under Providers.





On the Select
Trace Providers page, select one or more of the verbosity levels under Verbosity.





If you selected the ASPNET or WWW
Server trace provider in step 8, select one or more functional areas for the provider to trace under Areas of
the Select
Trace Providers page.

Click Finish.


Configuration

You can configure the
<traceFailedRequests>
element
at the server level in the ApplicationHost.config file or at the site level, application level, or URL level in the appropriate Web.config file.


ATTRIBUTES

None.


CHILD ELEMENTS

ElementDescription
add
Optional element.

Adds a path to the collection of path definitions.
remove
Optional element.

Removes a reference to a path from the path definitions collection.
clear
Optional element.

Removes all references to paths from the path definitions collection.


CONFIGURATION SAMPLE

The following configuration example configures tracing at the server level in the ApplicationHost.config file. It sets tracing for all .aspx files, uses the
<traceAreas>
element
to set the ASPNET provider
and trace against all ASP.NET areas, which areInfrastructure, Module, Page and AppServices.
The sample also uses the verbosity attribute
to set the amount of information returned to the tracing file to warning.
Lastly, the sample uses the
<failureDefinitions>
element
to trace only requests that generate a HTTP 404 status code.
<tracing>
<traceFailedRequests>
<add path="*.aspx">
<traceAreas>
<add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Warning" />
</traceAreas>
<failureDefinitions statusCodes="404" />
</add>
</traceFailedRequests>
</tracing>


Sample Code

The following examples enable verbose failed request tracing for HTTP 500 errors in ASP.NET content on all requests to *.aspx pages.


APPCMD.EXE

appcmd.exe set config "Contoso" -section:system.webServer/tracing/traceFailedRequests /+"[path='*.aspx']"

appcmd.exe set config "Contoso" -section:system.webServer/tracing/traceFailedRequests /+"[path='*.aspx'].traceAreas.[provider='ASPNET',areas='Infrastructure,Module,Page,AppServices',verbosity='Verbose']"

appcmd.exe set config "Contoso" -section:system.webServer/tracing/traceFailedRequests /[path='*.aspx'].failureDefinitions.statusCodes:"500"


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.GetWebConfiguration("Contoso");
ConfigurationSection traceFailedRequestsSection = config.GetSection("system.webServer/tracing/traceFailedRequests");
ConfigurationElementCollection traceFailedRequestsCollection = traceFailedRequestsSection.GetCollection();

ConfigurationElement addElement = traceFailedRequestsCollection.CreateElement("add");
addElement["path"] = @"*.aspx";

ConfigurationElementCollection traceAreasCollection = addElement.GetCollection("traceAreas");
ConfigurationElement addElement1 = traceAreasCollection.CreateElement("add");
addElement1["provider"] = @"ASPNET";
addElement1["areas"] = @"Infrastructure,Module,Page,AppServices";
addElement1["verbosity"] = @"Verbose";
traceAreasCollection.Add(addElement1);

ConfigurationElement failureDefinitionsElement = addElement.GetChildElement("failureDefinitions");
failureDefinitionsElement["statusCodes"] = @"500";
traceFailedRequestsCollection.Add(addElement);

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.GetWebConfiguration("Contoso")
Dim traceFailedRequestsSection As ConfigurationSection = config.GetSection("system.webServer/tracing/traceFailedRequests")
Dim traceFailedRequestsCollection As ConfigurationElementCollection = traceFailedRequestsSection.GetCollection

Dim addElement As ConfigurationElement = traceFailedRequestsCollection.CreateElement("add")
addElement("path") = "*.aspx"
Dim traceAreasCollection As ConfigurationElementCollection = addElement.GetCollection("traceAreas")
Dim addElement1 As ConfigurationElement = traceAreasCollection.CreateElement("add")
addElement1("provider") = "ASPNET"
addElement1("areas") = "Infrastructure,Module,Page,AppServices"
addElement1("verbosity") = "Verbose"
traceAreasCollection.Add(addElement1)

Dim failureDefinitionsElement As ConfigurationElement = addElement.GetChildElement("failureDefinitions")
failureDefinitionsElement("statusCodes") = "500"
traceFailedRequestsCollection.Add(addElement)

serverManager.CommitChanges()
End Sub
End Module


JAVASCRIPT

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Contoso";
var traceFailedRequestsSection = adminManager.GetAdminSection("system.webServer/tracing/traceFailedRequests", "MACHINE/WEBROOT/APPHOST/Contoso");
var traceFailedRequestsCollection = traceFailedRequestsSection.Collection;

var addElement = traceFailedRequestsCollection.CreateNewElement("add");
addElement.Properties.Item("path").Value = "*.aspx";
var traceAreasCollection = addElement.ChildElements.Item("traceAreas").Collection;

var addElement1 = traceAreasCollection.CreateNewElement("add");
addElement1.Properties.Item("provider").Value = "ASPNET";
addElement1.Properties.Item("areas").Value = "Infrastructure,Module,Page,AppServices";
addElement1.Properties.Item("verbosity").Value = "Verbose";
traceAreasCollection.AddElement(addElement1);

var failureDefinitionsElement = addElement.ChildElements.Item("failureDefinitions");
failureDefinitionsElement.Properties.Item("statusCodes").Value = "500";
traceFailedRequestsCollection.AddElement(addElement);

adminManager.CommitChanges();


VBSCRIPT

Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Contoso"
Set traceFailedRequestsSection = adminManager.GetAdminSection("system.webServer/tracing/traceFailedRequests", "MACHINE/WEBROOT/APPHOST/Contoso")
Set traceFailedRequestsCollection = traceFailedRequestsSection.Collection

Set addElement = traceFailedRequestsCollection.CreateNewElement("add")
addElement.Properties.Item("path").Value = "*.aspx"
Set traceAreasCollection = addElement.ChildElements.Item("traceAreas").Collection

Set addElement1 = traceAreasCollection.CreateNewElement("add")
addElement1.Properties.Item("provider").Value = "ASPNET"
addElement1.Properties.Item("areas").Value = "Infrastructure,Module,Page,AppServices"
addElement1.Properties.Item("verbosity").Value = "Verbose"
traceAreasCollection.AddElement addElement1

Set failureDefinitionsElement = addElement.ChildElements.Item("failureDefinitions")
failureDefinitionsElement.Properties.Item("statusCodes").Value = "500"
traceFailedRequestsCollection.AddElement addElement

adminManager.CommitChanges()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: