Activity 类

定义

表示具有要用于日志记录的上下文的操作。Represents an operation with context to be used for logging.

public ref class Activity : IDisposable
public ref class Activity
public class Activity : IDisposable
public class Activity
type Activity = class
    interface IDisposable
type Activity = class
Public Class Activity
Implements IDisposable
Public Class Activity
继承
Activity
实现

注解

Activity包含操作名称、ID、开始时间和持续时间、标记和行李。An Activity has an operation name, an ID, a start time and duration, tags, and baggage.

当前活动可以通过静态 Activity.Current 属性访问。The current activity can be accessed with the static Activity.Current property.

应通过调用构造函数来创建活动,并根据需要进行配置,然后使用 Start 方法(该方法维护活动和集的父子关系)启动 Activity.CurrentActivities should be created by calling the constructor, configured as necessary, and then started with the Start method, which maintains parent-child relationships for the activities and sets Activity.Current.

活动完成后,应使用 Activity.Stop() 方法停止。When an activity is finished, it should be stopped with the Activity.Stop() method.

没有 Activity 方法允许将异常转义为对错误输入的响应。No Activity methods allow exceptions to escape as a response to bad inputs. 将引发和捕获它们 (这允许调试器和监视器查看错误) ,但异常被取消,并且操作具有合理的 (通常不执行任何) 。They are thrown and caught (which allows debuggers and monitors to see the error), but the exception is suppressed, and the operation does something reasonable (typically it does nothing).

构造函数

Activity(String)

初始化 Activity 类的新实例。Initializes a new instance of the Activity class.

属性

ActivityTraceFlags

获取或设置与活动关联的标志(由 W3C ID 规范定义)。Gets or sets the flags (defined by the W3C ID specification) associated with the activity.

Baggage

获取键/值对的集合,它表示传递给此 Activity 的子元素的信息。Gets a collection of key/value pairs that represents information that is passed to children of this Activity.

Context

获取活动的上下文。Gets the context of the activity. 仅当活动启动时,上下文才会生效。Context becomes valid only if the activity has been started.

Current

获取或设置当前线程的当前操作 (Activity)。Gets or sets the current operation (Activity) for the current thread. 这会跨异步调用传递。This flows across async calls.

DefaultIdFormat

获取或设置 Activity 的默认 ID 格式。Gets or sets the default ID format for the Activity.

DisplayName

获取或设置活动的显示名称。Gets or sets the display name of the activity.

Duration

获取操作的持续时间。Gets the duration of the operation.

Events

获取附加到此活动的所有活动事件的列表。Gets the list of all the activity events attached to this activity.

ForceDefaultIdFormat

获取或设置一个值,该值确定 DefaultIdFormat 是否始终用于定义默认 ID 格式。Gets or sets a value that detrmines if the DefaultIdFormat is always used to define the default ID format.

Id

获取特定请求专属的标识符。Gets an identifier that is specific to a particular request.

IdFormat

获取 Id 的格式。Gets the format for the Id.

IsAllDataRequested

获取或设置一个值,它指示此活动是否该用所有传播信息和其他所有属性(如链接、标记和事件)进行填充。Gets or sets a value that indicates whether this activity should be populated with all the propagation information, as well as all the other properties, such as links, tags, and events.

Kind

获取跟踪中的活动、其父活动和子活动之间的关系。Gets the relationship between the activity, its parents, and its children in a trace.

Links

获取附加到此活动的所有活动链接的列表。Gets the list of all the activity links attached to this activity.

OperationName

获取操作名称。Gets the operation name.

Parent

获取创建此活动的父级 ActivityGets the parent Activity that created this activity.

ParentId

获取此活动父级的 ID。Gets the ID of this activity's parent.

ParentSpanId

获取父级的 SpanIdGets the parent's SpanId.

Recorded

获取一个值,指示是否已设置 W3CIdFlags.Recorded 标志。Gets a value that indicates whether the W3CIdFlags.Recorded flag is set.

RootId

获取此 Activity 的根 ID。Gets the root ID of this Activity.

Source

获取与此活动关联的活动源。Gets the activity source associated with this activity.

SpanId

获取 Id 的 SPAN 部分。Gets the SPAN part of the Id.

StartTimeUtc

获取操作开始的时间。Gets the time when the operation started.

TagObjects

获取表示要与活动一起记录的信息的标记列表。Gets the list of tags that represent information to log along with the activity. 此信息不会传递给该活动的子级。This information is not passed on to the children of this activity.

Tags

获取键/值对的集合,这些键/值对表示将与 Activity 一起记录到日志系统的信息。Gets a collection of key/value pairs that represent information that will be logged along with the Activity to the logging system.

TraceId

获取 Id 的 TraceId 部分。Gets the TraceId part of the Id.

TraceStateString

获取或设置 W3C tracestate 标头。Gets or sets the W3C tracestate header.

方法

AddBaggage(String, String)

更新 Activity,使用指定的键和值获取新的行李项。Updates the Activity to have a new baggage item with the specified key and value.

AddEvent(ActivityEvent)

将指定的活动事件添加到事件列表。Adds the specified activity event to the events list.

AddTag(String, Object)

更新活动,使标记具有额外的 keyvalueUpdates the activity to have a tag with an additional key and value.

AddTag(String, String)

更新 Activity,使用所提供的 keyvalue 获取新标记。Updates the Activity to have a new tag with the provided key and value.

Dispose()

如果活动已启动,则停止该活动,并通知任何事件侦听器。Stops the activity if it is already started and notifies any event listeners. 否则,不会有任何操作。Nothing will happen otherwise.

Dispose(Boolean)

当被派生类型替代时,此方法会释放所有已分配的资源。When overriden by a derived type, this method releases any allocated resources.

Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetBaggageItem(String)

返回通过 AddBaggage(String, String) 添加到活动的键值对的值。Returns the value of a key-value pair added to the activity with AddBaggage(String, String).

GetCustomProperty(String)

返回映射到指定属性名称的对象。Returns the object mapped to the specified property name.

GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
SetCustomProperty(String, Object)

将任何自定义对象附加到此活动。Attaches any custom object to this activity. 如果指定的 propertyName 之前与另一个对象关联,则会将属性更新为与新的 propertyValue 关联。If the specified propertyName was previously associated with another object, the property will be updated to be associated with the new propertyValue instead. 建议使用唯一属性名称,以避免与使用相同值的任何用户冲突。It is recommended to use a unique property name to avoid conflicts with anyone using the same value.

SetEndTime(DateTime)

更新 Activity,将其 Duration 设置为 StartTimeUtc 与指定的停止时间之间的差值。Updates the Activity to set its Duration as the difference between StartTimeUtc and the specified stop time.

SetIdFormat(ActivityIdFormat)

在开始前,设置此 Activity 的 ID 格式。Sets the ID format on this Activity before it is started.

SetParentId(ActivityTraceId, ActivitySpanId, ActivityTraceFlags)

使用 TraceId 和 SpanId 的 W3C 约定设置父 ID。Sets the parent ID using the W3C convention of a TraceId and a SpanId.

SetParentId(String)

更新此 Activity,以指示 ID 为 parentIdActivity 导致了此 ActivityUpdates this Activity to indicate that the Activity with an ID of parentId caused this Activity.

SetStartTime(DateTime)

设置此 Activity 的开始时间。Sets the start time of this Activity.

SetTag(String, Object)

使用输入键和值添加或更新活动标记。Adds or update the activity tag with the input key and value.

Start()

启动活动。Starts the activity.

Stop()

停止活动。Stops the activity.

ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

适用于