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
An Activity
has an operation name, an ID, a start time and duration, tags, and baggage.
The current activity can be accessed with the static Activity.Current property.
Activities 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.
When an activity is finished, it should be stopped with the Activity.Stop() method.
However, if you dispose the Activity
object, that stops it so you don't need to explicitly call Activity.Stop(). That simplifies the coding pattern. For more information, see the Dispose method.
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).
Gets or sets the flags (defined by the W3C ID specification) associated with the activity.
BaggageGets a collection of key/value pairs that represents information that is passed to children of this Activity.
ContextGets the context of the activity. Context becomes valid only if the activity has been started.
CurrentGets or sets the current operation (Activity) for the current thread. This flows across async calls.
DefaultIdFormatGets or sets the default ID format for the Activity.
DisplayNameGets or sets the display name of the activity.
DurationGets the duration of the operation.
EventsGets the list of all the activity events attached to this activity.
ForceDefaultIdFormatGets or sets a value that detrmines if the DefaultIdFormat is always used to define the default ID format.
HasRemoteParentGets a value that indicates whether the parent context was created from remote propagation.
IdGets an identifier that is specific to a particular request.
IdFormatGets the format for the Id.
IsAllDataRequestedGets 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.
IsStoppedGets a value that indicates whether this Activity object is stopped or not.
KindGets the relationship between the activity, its parents, and its children in a trace.
LinksGets the list of all the activity links attached to this activity.
OperationNameGets the operation name.
ParentGets the parent Activity that created this activity.
ParentIdGets the ID of this activity's parent.
ParentSpanIdGets the parent's SpanId.
RecordedGets a value that indicates whether the W3CIdFlags.Recorded flag is set.
RootIdGets the root ID of this Activity.
SourceGets the activity source associated with this activity.
SpanIdGets the SPAN part of the Id.
StartTimeUtcGets the time when the operation started.
StatusGets status code of the current activity object.
StatusDescriptionGets the status description of the current activity object.
TagObjectsGets 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.
TagsGets a collection of key/value pairs that represent information that will be logged along with the Activity to the logging system.
TraceIdGets the TraceId part of the Id.
TraceIdGeneratorWhen 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.
TraceStateStringGets or sets the W3C tracestate
header.
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.
AddException(Exception, TagList, DateTimeOffset) AddLink(ActivityLink) AddTag(String, Object)Updates the activity to have a tag with an additional key
and value
.
Updates the Activity to have a new tag with the provided key
and value
.
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 the ActivityEvent objects attached to this Activity object.
EnumerateLinks()Enumerates the ActivityLink 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 from Object) GetBaggageItem(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.
(Inherited from Object) GetTagItem(String)Returns the value of the Activity tag mapped to the input key. Returns null
if that key does not exist.
Gets the Type of the current instance.
(Inherited from Object) MemberwiseClone()Creates a shallow copy of the current Object.
(Inherited from Object) SetBaggage(String, String)Add or update the Activity baggage with the input key and value. If the input value is null
- 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 not null
- 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.
Attaches any custom object to this activity. 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.
Updates the Activity to set its Duration as the difference between StartTimeUtc and the specified stop time.
SetIdFormat(ActivityIdFormat)Sets the ID format on this Activity 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 this Activity to indicate that the Activity with an ID of parentId
caused this Activity.
Sets the start time of this Activity.
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 from Object) EventsCollaborate 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, see our contributor guide. In this articleWas this page helpful?
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4