Muokkaa

Jaa


DiagnosticListener.Subscribe Method

Definition

These methods allow adding a subscriber, and some of them provide optional event filtering methods.

Overloads

Subscribe(IObserver<KeyValuePair<String,Object>>)

Adds a subscriber.

Subscribe(IObserver<KeyValuePair<String,Object>>, Func<String,Object,Object,Boolean>)

Adds a subscriber, and optionally filters events based on their name and up to two context objects.

Subscribe(IObserver<KeyValuePair<String,Object>>, Predicate<String>)

Adds a subscriber, and optionally filters events based on their name.

Subscribe(IObserver<KeyValuePair<String,Object>>, Func<String,Object,Object,Boolean>, Action<Activity,Object>, Action<Activity,Object>)

Adds a subscriber, optionally filters events based on their name and up to two context objects, and specifies methods to call when providers import or export activites from outside the process.

Subscribe(IObserver<KeyValuePair<String,Object>>)

Source:
DiagnosticListener.cs
Source:
DiagnosticListener.cs
Source:
DiagnosticListener.cs
Source:
DiagnosticListener.cs
Source:
DiagnosticListener.cs

Adds a subscriber.

public:
 virtual IDisposable ^ Subscribe(IObserver<System::Collections::Generic::KeyValuePair<System::String ^, System::Object ^>> ^ observer);
public virtual IDisposable Subscribe (IObserver<System.Collections.Generic.KeyValuePair<string,object?>> observer);
public IDisposable Subscribe (IObserver<System.Collections.Generic.KeyValuePair<string,object>> observer);
public virtual IDisposable Subscribe (IObserver<System.Collections.Generic.KeyValuePair<string,object>> observer);
abstract member Subscribe : IObserver<System.Collections.Generic.KeyValuePair<string, obj>> -> IDisposable
override this.Subscribe : IObserver<System.Collections.Generic.KeyValuePair<string, obj>> -> IDisposable
Public Overridable Function Subscribe (observer As IObserver(Of KeyValuePair(Of String, Object))) As IDisposable
Public Function Subscribe (observer As IObserver(Of KeyValuePair(Of String, Object))) As IDisposable

Parameters

observer
IObserver<KeyValuePair<String,Object>>

A subscriber.

Returns

A reference to an interface that allows the listener to stop receiving notifications before the DiagnosticSource has finished sending them.

Implements

Applies to

Subscribe(IObserver<KeyValuePair<String,Object>>, Func<String,Object,Object,Boolean>)

Source:
DiagnosticListener.cs
Source:
DiagnosticListener.cs
Source:
DiagnosticListener.cs
Source:
DiagnosticListener.cs
Source:
DiagnosticListener.cs

Adds a subscriber, and optionally filters events based on their name and up to two context objects.

public:
 virtual IDisposable ^ Subscribe(IObserver<System::Collections::Generic::KeyValuePair<System::String ^, System::Object ^>> ^ observer, Func<System::String ^, System::Object ^, System::Object ^, bool> ^ isEnabled);
public virtual IDisposable Subscribe (IObserver<System.Collections.Generic.KeyValuePair<string,object?>> observer, Func<string,object?,object?,bool>? isEnabled);
public virtual IDisposable Subscribe (IObserver<System.Collections.Generic.KeyValuePair<string,object>> observer, Func<string,object,object,bool> isEnabled);
abstract member Subscribe : IObserver<System.Collections.Generic.KeyValuePair<string, obj>> * Func<string, obj, obj, bool> -> IDisposable
override this.Subscribe : IObserver<System.Collections.Generic.KeyValuePair<string, obj>> * Func<string, obj, obj, bool> -> IDisposable
Public Overridable Function Subscribe (observer As IObserver(Of KeyValuePair(Of String, Object)), isEnabled As Func(Of String, Object, Object, Boolean)) As IDisposable

Parameters

observer
IObserver<KeyValuePair<String,Object>>

A subscriber.

isEnabled
Func<String,Object,Object,Boolean>

A delegate that filters events based on their name and up to two context objects (which can be null), or null to if an event filter is not desirable.

Returns

A reference to an interface that allows the listener to stop receiving notifications before the DiagnosticSource has finished sending them.

Remarks

If isEnabled is not null, it indicates that some events are uninteresting can be skipped for efficiency.

A particular instrumentation site has the option of calling one or more IsEnabled overloads in which it passes the name of the event and up to two other (instrumentation site specific) objects as arguments. If any of these IsEnabled calls are made then this isEnabled predicate is invoked with passed values (if shorter overloads are used, null is passed for missing context objects).

This gives any particular instrumentation site the ability to pass up to two pieces of information to the subscriber to do sophisticated, efficient filtering. This requires more coupling between the instrumentation site and the subscriber code.

It is expected that a particular instrumentation site may call different overloads of IsEnabled for the same event, first calling IsEnabled(String), which calls the filter with two null context objects. If isEnabled returns true, it calls again with context objects. The isEnabled filter should be designed with this in mind.

Note that the isEnabled predicate is an optional optimization to allow the instrumentation site to avoid setting up the payload and calling Write(String, Object) when no subscriber cares about it. In particular, the instrumentation site has the option of ignoring the IsEnabled predicate (not calling it) and simply calling Write(String, Object). Thus, if the subscriber requires the filtering, it needs to do it itself.

If this parameter is null, no filtering is done (all overloads of IsEnabled return true).

Applies to

Subscribe(IObserver<KeyValuePair<String,Object>>, Predicate<String>)

Source:
DiagnosticListener.cs
Source:
DiagnosticListener.cs
Source:
DiagnosticListener.cs
Source:
DiagnosticListener.cs
Source:
DiagnosticListener.cs

Adds a subscriber, and optionally filters events based on their name.

public:
 virtual IDisposable ^ Subscribe(IObserver<System::Collections::Generic::KeyValuePair<System::String ^, System::Object ^>> ^ observer, Predicate<System::String ^> ^ isEnabled);
public virtual IDisposable Subscribe (IObserver<System.Collections.Generic.KeyValuePair<string,object?>> observer, Predicate<string>? isEnabled);
public virtual IDisposable Subscribe (IObserver<System.Collections.Generic.KeyValuePair<string,object>> observer, Predicate<string> isEnabled);
abstract member Subscribe : IObserver<System.Collections.Generic.KeyValuePair<string, obj>> * Predicate<string> -> IDisposable
override this.Subscribe : IObserver<System.Collections.Generic.KeyValuePair<string, obj>> * Predicate<string> -> IDisposable
Public Overridable Function Subscribe (observer As IObserver(Of KeyValuePair(Of String, Object)), isEnabled As Predicate(Of String)) As IDisposable

Parameters

observer
IObserver<KeyValuePair<String,Object>>

A subscriber.

isEnabled
Predicate<String>

A delegate that filters events based on their name (String). The delegate should return true if the event is enabled.

Returns

A reference to an interface that allows the listener to stop receiving notifications before the DiagnosticSource has finished sending them.

Remarks

If isEnabled is not null, some events are uninteresting and can be skipped for efficiency. The isEnabled predicate is an optional optimization to allow the instrumentation site to avoid setting up the payload and calling Write(String, Object) when no subscriber cares about it. In particular the instrumentation site has the option of ignoring the IsEnabled() predicate (not calling it) and simply calling Write(String, Object). Thus if the subscriber requires the filtering, it needs to do it itself.

If isEnabled is null, no filtering is done (all overloads of IsEnabled return true).

Applies to

Subscribe(IObserver<KeyValuePair<String,Object>>, Func<String,Object,Object,Boolean>, Action<Activity,Object>, Action<Activity,Object>)

Source:
DiagnosticSourceActivity.cs
Source:
DiagnosticSourceActivity.cs
Source:
DiagnosticSourceActivity.cs
Source:
DiagnosticSourceActivity.cs
Source:
DiagnosticSourceActivity.cs

Adds a subscriber, optionally filters events based on their name and up to two context objects, and specifies methods to call when providers import or export activites from outside the process.

public virtual IDisposable Subscribe (IObserver<System.Collections.Generic.KeyValuePair<string,object?>> observer, Func<string,object?,object?,bool>? isEnabled, Action<System.Diagnostics.Activity,object?>? onActivityImport = default, Action<System.Diagnostics.Activity,object?>? onActivityExport = default);
public virtual IDisposable Subscribe (IObserver<System.Collections.Generic.KeyValuePair<string,object>> observer, Func<string,object,object,bool> isEnabled, Action<System.Diagnostics.Activity,object> onActivityImport = default, Action<System.Diagnostics.Activity,object> onActivityExport = default);
abstract member Subscribe : IObserver<System.Collections.Generic.KeyValuePair<string, obj>> * Func<string, obj, obj, bool> * Action<System.Diagnostics.Activity, obj> * Action<System.Diagnostics.Activity, obj> -> IDisposable
override this.Subscribe : IObserver<System.Collections.Generic.KeyValuePair<string, obj>> * Func<string, obj, obj, bool> * Action<System.Diagnostics.Activity, obj> * Action<System.Diagnostics.Activity, obj> -> IDisposable
Public Overridable Function Subscribe (observer As IObserver(Of KeyValuePair(Of String, Object)), isEnabled As Func(Of String, Object, Object, Boolean), Optional onActivityImport As Action(Of Activity, Object) = Nothing, Optional onActivityExport As Action(Of Activity, Object) = Nothing) As IDisposable

Parameters

observer
IObserver<KeyValuePair<String,Object>>

A subscriber.

isEnabled
Func<String,Object,Object,Boolean>

A delegate that filters events based on their name and up to two context objects (which can be null), or null if an event filter is not desirable.

onActivityImport
Action<Activity,Object>

An action delegate that receives the activity affected by an external event and an object that represents the incoming request.

onActivityExport
Action<Activity,Object>

An action delegate that receives the activity affected by an external event and an object that represents the outgoing request.

Returns

A reference to an interface that allows the listener to stop receiving notifications before the DiagnosticSource has finished sending them.

Remarks

If isEnabled is non-null, some events are uninteresting can be skipped for efficiency.

You can also supply 'onActivityImport' and 'onActivityExport' methods that are called when providers importing or export activities from outside the process (for example, from HTTP requests). These methods are called after importing or exporting the activity and can be used to modify the activity or the outgoing request to add policy.

Applies to