Movatterモバイル変換


[0]ホーム

URL:


Skip to main contentSkip to in-page navigation

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit editor mode

Activity Class

Definition

Namespace:
System.Diagnostics
Assembly:
System.Diagnostics.DiagnosticSource.dll
Package:
System.Diagnostics.DiagnosticSource v10.0.0
Source:
Activity.cs
Source:
Activity.cs
Source:
Activity.cs
Source:
Activity.cs
Source:
Activity.cs

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

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 ActivityImplements IDisposable
Public Class Activity
Inheritance
Activity
Implements

Remarks

AnActivity has an operation name, an ID, a start time and duration, tags, and baggage.

The current activity can be accessed with the staticActivity.Current property.

Activities should be created by calling the constructor, configured as necessary, and then started with theStart method, which maintains parent-child relationships for the activities and setsActivity.Current.

When an activity is finished, it should be stopped with theActivity.Stop() method.

However, if you dispose theActivity object, that stops it so you don't need to explicitly callActivity.Stop(). That simplifies the coding pattern. For more information, see theDispose method.

NoActivity 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).

Constructors

NameDescription
Activity(String)

Initializes a new instance of theActivity class.

Properties

NameDescription
ActivityTraceFlags

Gets or sets the flags (defined by the W3C ID specification) associated with the activity.

Baggage

Gets a collection of key/value pairs that represents information that is passed to children of thisActivity.

Context

Gets the context of the activity. Context becomes valid only if the activity has been started.

Current

Gets or sets the current operation (Activity) for the current thread. This flows across async calls.

DefaultIdFormat

Gets or sets the default ID format for theActivity.

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

Gets or sets a value that detrmines if theDefaultIdFormat is always used to define the default ID format.

HasRemoteParent

Gets a value that indicates whether the parent context was created from remote propagation.

Id

Gets an identifier that is specific to a particular request.

IdFormat

Gets the format for theId.

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.

IsStopped

Gets a value that indicates whether thisActivity object is stopped or not.

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

Gets the parentActivity that created this activity.

ParentId

Gets the ID of this activity's parent.

ParentSpanId

Gets the parent'sSpanId.

Recorded

Gets a value that indicates whether the W3CIdFlags.Recorded flag is set.

RootId

Gets the root ID of thisActivity.

Source

Gets the activity source associated with this activity.

SpanId

Gets the SPAN part of theId.

StartTimeUtc

Gets the time when the operation started.

Status

Gets status code of the current activity object.

StatusDescription

Gets the status description of the current activity object.

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

Gets a collection of key/value pairs that represent information that will be logged along with theActivity to the logging system.

TraceId

Gets the TraceId part of theId.

TraceIdGenerator

When starting an Activity which does not have a parent context, the Trace Id will automatically be generated using random numbers.TraceIdGenerator can be used to override the runtime's default Trace Id generation algorithm.

TraceStateString

Gets or sets the W3Ctracestate header.

Methods

NameDescription
AddBaggage(String, String)

Updates theActivity to have a new baggage item with the specified key and value.

AddEvent(ActivityEvent)

Adds the specified activity event to the events list.

AddException(Exception, TagList, DateTimeOffset)

Add anActivityEvent object containing the exception information to theEvents list.

AddLink(ActivityLink)

Adds anActivityLink to theLinks list.

AddTag(String, Object)

Updates the activity to have a tag with an additionalkey andvalue.

AddTag(String, String)

Updates theActivity to have a new tag with the providedkey andvalue.

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.

EnumerateEvents()

Enumerates theActivityEvent objects attached to this Activity object.

EnumerateLinks()

Enumerates theActivityLink objects attached to this Activity object.

EnumerateTagObjects()

Enumerates the tags attached to this Activity object.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited fromObject)
GetBaggageItem(String)

Returns the value of a key-value pair added to the activity withAddBaggage(String, String).

GetCustomProperty(String)

Returns the object mapped to the specified property name.

GetHashCode()

Serves as the default hash function.

(Inherited fromObject)
GetTagItem(String)

Returns the value of the Activity tag mapped to the input key.Returnsnull if that key does not exist.

GetType()

Gets theType of the current instance.

(Inherited fromObject)
MemberwiseClone()

Creates a shallow copy of the currentObject.

(Inherited fromObject)
SetBaggage(String, String)

Add or update the Activity baggage with the input key and value.If the input value isnull - if the collection has any baggage with the same key, then this baggage will get removed from the collection.- otherwise, nothing will happen and the collection will not change.If the input value is notnull - if the collection has any baggage with the same key, then the value mapped to this key will get updated with the new input value.- otherwise, the key and value will get added as a new baggage to the collection.Baggage item will be updated/removed only if it was originaly added to the current activity. Items inherited from the parents will not be changed/removed, new item would be added to current activity baggage instead.

SetCustomProperty(String, Object)

Attaches any custom object to this activity. If the specifiedpropertyName was previously associated with another object, the property will be updated to be associated with the newpropertyValue instead. It is recommended to use a unique property name to avoid conflicts with anyone using the same value.

SetEndTime(DateTime)

Updates theActivity to set itsDuration as the difference betweenStartTimeUtc and the specified stop time.

SetIdFormat(ActivityIdFormat)

Sets the ID format on thisActivity before it is started.

SetParentId(ActivityTraceId, ActivitySpanId, ActivityTraceFlags)

Sets the parent ID using the W3C convention of a TraceId and a SpanId.

SetParentId(String)

Updates thisActivity to indicate that theActivity with an ID ofparentId caused thisActivity.

SetStartTime(DateTime)

Sets the start time of thisActivity.

SetStatus(ActivityStatusCode, String)

Sets the status code and description on the current activity object.

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.

(Inherited fromObject)

Events

NameDescription
CurrentChanged

Occurs when theCurrent value changes.

Applies to

Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, seeour contributor guide.

Feedback

Was this page helpful?

YesNoNo

Need help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?

In this article

Was this page helpful?

YesNo
NoNeed help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?