Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class System.​Diagnostics.​DiagnosticListener
Assembly: System.Diagnostics.DiagnosticSource
Inheritance: object → DiagnosticSource → DiagnosticListener
Implemented Interfaces
Provides an implementation of the abstract <see cref="T:System.Diagnostics.DiagnosticSource" /> class that represents a named place to which a source sends its information (events).
Properties
public static
IObservable<​DiagnosticListener>
AllListeners
Gets the collection of listeners for this <see cref="T:System.Diagnostics.DiagnosticListener" /> .
public
string
Name
Gets the name of this <see cref="T:System.Diagnostics.DiagnosticListener" /> .
Methods
public
void
Dispose​()
Disposes the NotificationListeners.
public
bool
IsEnabled​()
Determines whether there are any registered subscribers.
Returns <see langword="true" /> if there are any registered subscribers, <see langword="false" /> otherwise.
public
bool
IsEnabled​(string name)
Checks whether the <see cref="T:System.Diagnostics.DiagnosticListener" /> is enabled.
Returns <see langword="true" /> if notifications are enabled; otherwise, <see langword="false" /> .
name
The name of the event to check.
public
bool
IsEnabled​(string name,
object arg1,
object arg2 = null)
Checks if any subscriber to the diagnostic events is interested in receiving events with this name. Subscribers indicate their interest using a delegate provided in <see cref="Overload:System.Diagnostics.DiagnosticListener.Subscribe" /> .
Returns <see langword="true" /> if it is enabled, <see langword="false" /> otherwise.
name
The name of the event to check.
arg1
The object that represents a context.
arg2
The object that represents a context.
public
IDisposable
Subscribe​(IObserver<​Collections.​Generic.​KeyValuePair<​string, object>> observer)
Adds a subscriber.
Returns A reference to an interface that allows the listener to stop receiving notifications before the <see cref="T:System.Diagnostics.DiagnosticSource" /> has finished sending them.
observer
A subscriber.
public
IDisposable
Subscribe​(IObserver<​Collections.​Generic.​KeyValuePair<​string, object>> observer,
Func?<​string, object, object, bool> isEnabled)
Adds a subscriber, and optionally filters events based on their name and up to two context objects.
Returns A reference to an interface that allows the listener to stop receiving notifications before the <see cref="T:System.Diagnostics.DiagnosticSource" /> has finished sending them.
observer
A subscriber.
isEnabled
A delegate that filters events based on their name and up to two context objects (which can be <see langword="null" /> ), or <see langword="null" /> to if an event filter is not desirable.
public
IDisposable
Subscribe​(IObserver<​Collections.​Generic.​KeyValuePair<​string, object>> observer,
Predicate?<​string> isEnabled)
Adds a subscriber, and optionally filters events based on their name.
Returns A reference to an interface that allows the listener to stop receiving notifications before the <see cref="T:System.Diagnostics.DiagnosticSource" /> has finished sending them.
observer
A subscriber.
isEnabled
A delegate that filters events based on their name ( <see cref="T:System.String" /> ). The delegate should return <see langword="true" /> if the event is enabled.
public
string
ToString​()
Returns a string with the name of this DiagnosticListener.
Returns The name of this DiagnosticListener.
public
void
Write​(string name,
object value)
Logs a notification.
name
The name of the event to log.
value
An object that represents the payload for the event.
public
void
OnActivityExport​(Activity activity,
object payload)
Invokes the OnActivityExport method of all the subscribers.
activity
The activity affected by an external event.
payload
An object that represents the outgoing request.
public
void
OnActivityImport​(Activity activity,
object payload)
Invokes the OnActivityImport method of all the subscribers.
activity
The activity affected by an external event.
payload
An object that represents the incoming request.
public
IDisposable
Subscribe​(IObserver<​Collections.​Generic.​KeyValuePair<​string, object>> observer,
Func?<​string, object, object, bool> isEnabled,
Action?<​Activity, object> onActivityImport = null,
Action?<​Activity, object> onActivityExport = null)
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.
Returns A reference to an interface that allows the listener to stop receiving notifications before the <see cref="T:System.Diagnostics.DiagnosticSource" /> has finished sending them.
observer
A subscriber.
isEnabled
A delegate that filters events based on their name and up to two context objects (which can be <see langword="null" /> ), or <see langword="null" /> if an event filter is not desirable.
onActivityImport
An action delegate that receives the activity affected by an external event and an object that represents the incoming request.
onActivityExport
An action delegate that receives the activity affected by an external event and an object that represents the outgoing request.
public
void
Write​(string name,
T value)
Inherited from DiagnosticSource
Provides a generic way of logging complex payloads.
name
The name of the event being written.
value
An object that represents the value being passed as a payload for the event. This is often an anonymous type that contains several subvalues.
public
Activity
StartActivity​(Activity activity,
object args)
Inherited from DiagnosticSource
Starts an <see cref="T:System.Diagnostics.Activity" /> and writes a start event.
Returns The started activity for convenient chaining.
activity
The <see cref="T:System.Diagnostics.Activity" /> to be started.
args
An object that represent the value being passed as a payload for the event.
public
Activity
StartActivity​(Activity activity,
T args)
Inherited from DiagnosticSource
Starts an <xref data-throw-if-not-resolved="true" uid="System.Diagnostics.Activity"></xref> and writes a start event.
Returns The started activity for convenient chaining.
activity
The <xref data-throw-if-not-resolved="true" uid="System.Diagnostics.Activity"></xref> to be started.
args
An object that represent the value being passed as a payload for the event.
public
void
StopActivity​(Activity activity,
object args)
Inherited from DiagnosticSource
Stops the given <see cref="T:System.Diagnostics.Activity" /> , maintains the global <see cref="P:System.Diagnostics.Activity.Current" /> activity, and notifies consumers that the <see cref="T:System.Diagnostics.Activity" /> was stopped.
activity
The activity to be stopped.
args
An object that represents the value passed as a payload for the event.
public
void
StopActivity​(Activity activity,
T args)
Inherited from DiagnosticSource
Starts an <xref data-throw-if-not-resolved="true" uid="System.Diagnostics.Activity"></xref> and writes a start event.
Returns The started activity for convenient chaining.
activity
The <xref data-throw-if-not-resolved="true" uid="System.Diagnostics.Activity"></xref> to be started.
args
An object that represent the value being passed as a payload for the event.
public
bool
Equals​(object obj)
Inherited from object
protected
void
Finalize​()
Inherited from object
public
int
GetHashCode​()
Inherited from object
protected
object
MemberwiseClone​()
Inherited from object