Added tracing support for the MQTT client

The M2Mqtt library is now at release with the new tracing feature in debugging mode.

The project has the new Trace class that exposes the static member TraceListener declared as the following delegate :

// delegate for writing trace
public delegate void WriteTrace(string format, params object[] args);

In this way, it is possibile to chose our preferred tracing mode setting a method to this delegate. Furthermore, it is possibile to set the tracing level using thet static member TraceLevel with the following possible values :

/// <summary>
/// Tracing levels
/// </summary>
public enum TraceLevel
    Error = 0x01,
    Warning = 0x02,
    Information = 0x04,
    Verbose = 0x0F,
    Frame = 0x10

A simple example of tracing usage could be the following :

Trace.TraceLevel = MqttUtility.TraceLevel.Verbose | MqttUtility.TraceLevel.Frame;
Trace.TraceListener = (f, a) => System.Diagnostics.Trace.WriteLine(System.String.Format(f, a));

In this case, using a lambda expression, all tracing messages are printed in the Visual Studio output window.

SEND CONNECT(protocolName:MQIsdp,protocolVersion:3,clientId:testId,willFlag:False,willRetain:False,willQosLevel:2,willTopic:,willMessage:,cleanSession:False,keepAlivePeriod:60)
RECV CONNACK(returnCode:0)
SEND SUBSCRIBE(messageId:1,topics:[/foo/#,/foo/+/baz],qosLevels:0202)
RECV SUBACK(messageId:1,grantedQosLevels:0202)
RECV PUBLISH(messageId:1,topic:/foo,message:48656C6C6F)
SEND PUBREC(messageId:1)
RECV PUBREL(messageId:1)
SEND PUBCOMP(messageId:1)
SEND PUBLISH(messageId:2,topic:/thank,message:5468616E6B20596F7520212031)
RECV PUBREC(messageId:2)
SEND PUBREL(messageId:2)
RECV PUBCOMP(messageId:2)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s