DiagnosticListener
public class DiagnosticListener : DiagnosticSource, IObservable<KeyValuePair<string, object>>, IDisposable
A DiagnosticListener is something that forwards on events written with DiagnosticSource.
It is an IObservable (has Subscribe method), and it also has a Subscribe overload that
lets you specify a 'IsEnabled' predicate that users of DiagnosticSource will use for
'quick checks'.
The item in the stream is a KeyValuePair[string, object] where the string is the name
of the diagnostic item and the object is the payload (typically an anonymous type).
There may be many DiagnosticListeners in the system, but we encourage the use of
The DiagnosticSource.DefaultSource which goes to the DiagnosticListener.DefaultListener.
If you need to see 'everything' you can subscribe to the 'AllListeners' event that
will fire for every live DiagnosticListener in the appdomain (past or present).
Please See the DiagnosticSource Users Guide
https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.DiagnosticSource/src/DiagnosticSourceUsersGuide.md
for instructions on its use.
When you subscribe to this you get callbacks for all NotificationListeners in the appdomain
as well as those that occurred in the past, and all future Listeners created in the future.
When a DiagnosticListener is created it is given a name. Return this.
Make a new DiagnosticListener, it is a NotificationSource, which means the returned result can be used to
log notifications, but it also has a Subscribe method so notifications can be forwarded
arbitrarily. Thus its job is to forward things from the producer to all the listeners
(multi-casting). Generally you should not be making your own DiagnosticListener but use the
DiagnosticListener.Default, so that notifications are as 'public' as possible.
Clean up the NotificationListeners. Notification listeners do NOT DIE ON THEIR OWN
because they are in a global list (for discoverability). You must dispose them explicitly.
Note that we do not do the Dispose(bool) pattern because we frankly don't want to support
subclasses that have non-managed state.
public virtual IDisposable Subscribe(IObserver<KeyValuePair<string, object>> observer, Predicate<string> isEnabled)
Add a subscriber (Observer). If 'IsEnabled' == null (or not present), then the Source's IsEnabled
will always return true.
Same as other Subscribe overload where the predicate is assumed to always return true.