服务器类型 |
https://learn.microsoft.com/zh-cn/iis/configuration/system.webserver/tracing/tracefailedrequests/ |
慷慨的柿子
4 月前 |
<traceFailedRequests>
元素可用于为网站、应用程序或目录配置失败请求跟踪。 此元素可以包含定义跟踪规则的
<add>
元素集合,后者指定规则应用到的请求 URL 扩展、要启用的跟踪提供程序和区域以及导致此规则记录事件的条件。
完成 IIS 7 及更高版本的默认安装后,必须安装跟踪角色服务才能使用失败请求跟踪。 安装角色服务后,仍必须在站点级别、应用程序级别或目录级别启用失败请求跟踪。
打开 Internet Information Services (IIS) 管理器:
如果使用的是 Windows Server 2012 或 Windows Server 2012 R2:
如果使用的是 Windows 8 或 Windows 8.1:
如果使用的是 Windows Server 2008 或 Windows Server 2008 R2:
如果使用的是 Windows Vista 或 Windows 7:
打开 Internet Information Services (IIS) 管理器:
如果使用的是 Windows Server 2012 或 Windows Server 2012 R2:
如果使用的是 Windows 8 或 Windows 8.1:
如果使用的是 Windows Server 2008 或 Windows Server 2008 R2:
如果使用的是 Windows Vista 或 Windows 7:
在“定义跟踪条件”
页上,选择要跟踪的条件,然后单击“下一页”
。 跟踪条件可以包括状态代码、请求应采用的时间限制或事件严重性的任意组合。 如果指定所有条件,则满足的第一个条件将生成失败的请求跟踪日志文件。
在“选择跟踪提供程序”
页上,选择“提供程序”
下的一个或多个跟踪提供程序。
在“选择跟踪提供程序”
页上,选择“详细程度”
下的一个或多个详细级别。
如果在步骤 8 中选择了“ASPNET” 或“WWW 服务器” 跟踪提供程序,请在“选择跟踪提供程序” 页的“区域” 下选择提供程序要跟踪的一个或多个功能区域。
单击“完成”。
使用 ApplicationHost.config 文件,可以在服务器级别配置
<traceFailedRequests>
元素,使用相应的 Web.config 文件,则可以在站点级别、应用程序级别或 URL 级别配置。
以下配置示例展示了如何在 ApplicationHost.config 文件中的服务器级别配置跟踪。 它为所有 .aspx 文件设置跟踪,使用
<traceAreas>
元素设置“ASPNET”
提供程序,并针包括“基础结构”
、“模块”
、“页面”
和“AppServices”
在内的所有 ASP.NET 区域进行跟踪。 此示例还使用“详细程度”
属性将返回到跟踪文件的信息量设置为“警告”
。 最后,该示例使用
<failureDefinitions>
元素仅跟踪生成 HTTP 404 状态代码的请求。
<tracing>
<traceFailedRequests>
<add path="*.aspx">
<traceAreas>
<add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Warning" />
</traceAreas>
<failureDefinitions statusCodes="404" />
</traceFailedRequests>
</tracing>
以下示例为所有 *.aspx 页面请求的 ASP.NET 内容 HTTP 500 错误启用详细失败请求跟踪。
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"
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()
知识渊博的冰棍 · 无法启动Zabbix -server的docker容器:无法使用数据库"zabbix":其“用户”表为空(这是Zabbix代理数据库吗?) - 问答 - 腾讯云开发者社区-腾讯云 1 年前 |
机灵的绿茶 · 总结npm常见错误 - 掘金 1 年前 |