WebThreadInformation 类
定义
提供有关 ASP.NET 进程中某个线程的状态的信息。Provides information about the state of a thread in an ASP.NET process.
public ref class WebThreadInformation sealed
public sealed class WebThreadInformation
type WebThreadInformation = class
Public NotInheritable Class WebThreadInformation
- 继承
-
WebThreadInformation
示例
下面的代码示例包含两个部分。The following code example has two parts. 第一种是配置文件的摘录,使 ASP.NET 可以使用使用该类型的自定义事件 WebThreadInformation 。The first is an excerpt of a configuration file that enables ASP.NET to use a custom event that uses the WebThreadInformation type. 第二个示例演示如何实现使用类型的自定义事件 WebThreadInformation 。The second shows how to implement the custom event that uses the WebThreadInformation type.
确保在适当的时间引发自定义事件,即,当引发其替换的等效系统运行状况事件时。Ensure that your custom event is raised at the proper time, that is, when the equivalent system health event it replaces would be raised.
<healthMonitoring
heartBeatInterval="0" enabled="true">
<profiles>
<add name="Custom"
minInstances="1"
maxLimit="Infinite"
minInterval="00:00:00" />
</profiles>
<eventMappings>
<add
name="SampleWebThreadInformation"
type="SamplesAspNet.SampleWebThreadInformation,webthreadinformation, Version=1.0.1782.29648, Culture=neutral, PublicKeyToken=b3283a2de7dd3f27, processorArchitecture=MSIL" />
</eventMappings>
<rules>
<add name="Custom Web Thread Info Event"
eventName="SampleWebThreadInformation"
provider="EventLogProvider"
profile="Custom" />
</rules>
</healthMonitoring>
using System;
using System.Text;
using System.Web;
using System.Web.Management;
namespace SamplesAspNet
{
// Implements a custom WebErrorstEvent that uses the
// WebThreadInformation.
public class SampleWebThreadInformation :
WebErrorEvent
{
private StringBuilder eventInfo;
// Instantiate events identified
// only by their event code.
public SampleWebThreadInformation(
string msg, object eventSource,
int eventCode, Exception e)
:
base(msg, eventSource, eventCode, e)
{
// Perform custom initialization.
eventInfo = new StringBuilder();
eventInfo.Append(string.Format(
"Event created at: {0}",
EventTime.ToString()));
}
// Raises the event.
public override void Raise()
{
// Perform custom processing.
eventInfo.Append(string.Format(
"Event raised at: {0}",
EventTime.ToString()));
// Raise the event.
base.Raise();
}
// Get the impersonation mode.
public string GetThreadImpersonation()
{
return (string.Format(
"Is impersonating: {0}",
ThreadInformation.IsImpersonating.ToString()));
}
// Get the stack trace.
public string GetThreadStackTrace()
{
return (string.Format(
"Stack trace: {0}",
ThreadInformation.StackTrace));
}
// Get the account name.
public string GetThreadAccountName()
{
return (string.Format(
"Request user host address: {0}",
ThreadInformation.ThreadAccountName));
}
// Get the task Id.
public string GetThreadId()
{
// Get the request principal.
return (string.Format(
"Thread Id: {0}",
ThreadInformation.ThreadID.ToString()));
}
// Formats Web request event information.
public override void FormatCustomEventDetails(
WebEventFormatter formatter)
{
// Add custom data.
formatter.AppendLine("");
formatter.AppendLine(
"Custom Thread Information:");
formatter.IndentationLevel += 1;
// Display the thread information obtained
formatter.AppendLine(GetThreadImpersonation());
formatter.AppendLine(GetThreadStackTrace());
formatter.AppendLine(GetThreadAccountName());
formatter.AppendLine(GetThreadId());
formatter.IndentationLevel -= 1;
formatter.AppendLine(eventInfo.ToString());
}
}
}
Imports System.Text
Imports System.Web
Imports System.Web.Management
' Implements a custom WebErrorstEvent that uses the
' WebThreadInformation.
Public Class SampleWebThreadInformation
Inherits WebErrorEvent
Private eventInfo As StringBuilder
' Instantiate events identified
' only by their event code.
Public Sub New(ByVal msg As String, _
ByVal eventSource As Object, _
ByVal eventCode As Integer, ByVal e As Exception)
MyBase.New(msg, eventSource, eventCode, e)
' Perform custom initialization.
eventInfo = New StringBuilder()
eventInfo.Append(String.Format("Event created at: {0}", EventTime.ToString()))
End Sub
' Raises the event.
Public Overrides Sub Raise()
' Perform custom processing.
eventInfo.Append(String.Format( _
"Event raised at: {0}", EventTime.ToString()))
' Raise the event.
MyBase.Raise()
End Sub
' Get the impersonation mode.
Public Function GetThreadImpersonation() As String
Return String.Format( _
"Is impersonating: {0}", _
ThreadInformation.IsImpersonating.ToString())
End Function 'GetThreadImpersonation
' Get the stack trace.
Public Function GetThreadStackTrace() As String
Return String.Format( _
"Stack trace: {0}", _
ThreadInformation.StackTrace)
End Function 'GetThreadStackTrace
' Get the account name.
Public Function GetThreadAccountName() As String
Return String.Format( _
"Request user host address: {0}", _
ThreadInformation.ThreadAccountName)
End Function 'GetThreadAccountName
' Get the task Id.
Public Function GetThreadId() As String
' Get the request principal.
Return String.Format( _
"Thread Id: {0}", _
ThreadInformation.ThreadID.ToString())
End Function 'GetThreadId
' Formats Web request event information.
Public Overrides Sub FormatCustomEventDetails( _
ByVal formatter As WebEventFormatter)
' Add custom data.
formatter.AppendLine("")
formatter.AppendLine( _
"Custom Thread Information:")
formatter.IndentationLevel += 1
' Display the thread information obtained
formatter.AppendLine(GetThreadImpersonation())
formatter.AppendLine(GetThreadStackTrace())
formatter.AppendLine(GetThreadAccountName())
formatter.AppendLine(GetThreadId())
formatter.IndentationLevel -= 1
formatter.AppendLine(eventInfo.ToString())
End Sub
End Class
注解
ASP.NET health monitoring 允许生产和运营人员管理已部署的 Web 应用程序。ASP.NET health monitoring allows production and operations staff to manage deployed Web applications. System.Web.Management命名空间包含的运行状况事件类型负责打包应用程序运行状况数据,以及负责处理此数据的提供程序类型。The System.Web.Management namespace contains the health-event types responsible for packaging application health-status data and the provider types responsible for processing this data. 它还包含在运行状况事件的管理过程中可帮助的支持类型。It also contains supporting types that help during the management of health events.
类的实例 WebThreadInformation 包含使用 WebErrorEvent 类型或类型获得的信息 WebRequestErrorEvent 。Instances of the WebThreadInformation class contain information that is obtained using either the WebErrorEvent type or the WebRequestErrorEvent type.
应用程序需要适当的权限才能访问此类型提供的受保护信息。Your application needs the appropriate permissions to access protected information provided by this type.
备注
在大多数情况下,你将能够使用已实现的 ASP.NET health 监视类型,并且将通过在 "配置" 部分中指定值来控制运行状况监视系统 healthMonitoring 。In most cases you will be able to use the ASP.NET health-monitoring types as implemented, and you will control the health-monitoring system by specifying values in the healthMonitoring configuration section. 还可以从运行状况监视类型派生,以创建自己的自定义事件和提供程序。You can also derive from the health-monitoring types to create your own custom events and providers. 有关创建自定义事件类的示例,请参阅本主题中提供的示例。For an example of creating a custom event class, see the example provided in this topic.
属性
| IsImpersonating |
获取当前的线程模拟模式。Gets the current thread-impersonation mode. |
| StackTrace |
获取当前的线程管理的堆栈跟踪。Gets the current thread-managed stack trace. |
| ThreadAccountName |
获取线程帐户名。Gets the thread account name. |
| ThreadID |
获取当前线程标识符。Gets the current thread identifier. |
方法
| Equals(Object) |
确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object. (继承自 Object) |
| FormatToString(WebEventFormatter) |
格式化线程相关信息。Formats thread-related information. |
| GetHashCode() |
作为默认哈希函数。Serves as the default hash function. (继承自 Object) |
| GetType() |
获取当前实例的 Type。Gets the Type of the current instance. (继承自 Object) |
| MemberwiseClone() |
创建当前 Object 的浅表副本。Creates a shallow copy of the current Object. (继承自 Object) |
| ToString() |
返回表示当前对象的字符串。Returns a string that represents the current object. (继承自 Object) |