The M2Mqtt library is now at 3.4.0.0 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 :

   1: // delegate for writing trace
   2: 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 :

   1: /// <summary>
   2: /// Tracing levels
   3: /// </summary>
   4: public enum TraceLevel
   5: {
   6:     Error = 0x01,
   7:     Warning = 0x02,
   8:     Information = 0x04,
   9:     Verbose = 0x0F,
  10:     Frame = 0x10
  11: }

A simple example of tracing usage could be the following :

   1: Trace.TraceLevel = MqttUtility.TraceLevel.Verbose | MqttUtility.TraceLevel.Frame;
   2: 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.

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

The new version is available on CodePlex, Nuget and Microsoft Code Gallery. We also have the update for M2Mqtt4CE for our Windows Embedded Compact 2013 image !