Write metrics to the trace log

Component: Metrics
NuGet Package NServiceBus.Metrics (1.x)
Target NServiceBus Version: 6.x

Illustrates how to write metrics information to the trace log.

There are many ways to look at the trace log for example via the DbgView utility provided by Sysinternals

DbgView by Sysinternals

This shows the output of NServiceBus.Metrics 3.x variant.

Running the sample

  1. Run the solution in the Visual Studio debugger. A console application will start.
  2. Press the 'enter' key to send a message.
  3. Check the debug output window for metric information being written to the trace log.

Sending metric data to Trace Log

var metrics = endpointConfiguration.EnableMetrics();
metrics.RegisterObservers(
    register: context =>
    {
        foreach (var duration in context.Durations)
        {
            duration.Register(
                observer: length =>
                {
                    Trace.WriteLine($"Duration: '{duration.Name}'. Value: '{length}'");
                });
        }
        foreach (var signal in context.Signals)
        {
            signal.Register(
                observer: () =>
                {
                    Trace.WriteLine($"Signal: '{signal.Name}'");
                });
        }
    });

Related Articles


Last modified