The trace extensions are used to instrument IObservable<T>
. Tracing is similar in usage and behavior to the Do
extension in Rx, although the trace extensions provide additional semantics and features that are specific for tracing.
Tracing is often used to log the data in a sequence. It can also be used to log error and completion notifications without affecting the behavior of the sequence. Reactive sequences have subscriptions and cancellation behaviors, which can also be logged. There
are also trace extensions that accept a string identifying the current observer, or an identifier can be generated automatically.
The trace extensions provide minimalistic methods that write to the
. They also provide overloads that accept format strings, format functions and a
object, for more control over the output.
Using Third-Party Logging, such as Log4Net and NLog
Tracing in Rxx uses the built-in .NET tracing APIs because they provide a simple yet powerful instrumentation model for all applications, which is also consistent with the tracing provided by various APIs in the .NET Framework, such as
Windows Presentation Foundation (WPF) tracing
Windows Communication Foundation (WCF) tracing
If your application already depends upon a third-party logging library, such as Log4Net or NLog, then you can write an adapter class that derives from
to redirect trace output to your preferred logging API. You can also reuse your listener to redirect output from the tracing in .NET APIs for network events, WCF and WPF.
The following C# code snippet was taken from Rxx Labs, which is available on the
tab. The lab defines an observable query using the Rx Timer
operator and the Rxx
output is redirected to the console by an instance of the
class, which is provided by the .NET Framework.
static void Main()
var xs = Observable
.TraceOnNext(value => "OnNext: " + value)
var query = Observable
.Select(_ => xs)
The entire tracing API is available in the Rxx library for the full .NET Framework 4.0 only.
Silverlight and Windows Phone do not currently include the .NET tracing APIs, thus Rxx's trace extensions are not included on these platforms.
Download the labs application for .NET 4.0 and then run the Reactive / Tracing
Interactive / Tracing
labs. These labs contain working examples of some of the trace extensions in Rxx. The source code for the labs is displayed in the application, for your convenience.
For more information, see
Rxx Hands-on Labs