You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 7 година
пре 7 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. namespace MQTTnet.Core.Diagnostics
  3. {
  4. public static class MqttTrace
  5. {
  6. public static event EventHandler<MqttTraceMessagePublishedEventArgs> TraceMessagePublished;
  7. public static void Verbose(string source, string message)
  8. {
  9. Publish(source, MqttTraceLevel.Verbose, null, message);
  10. }
  11. public static void Information(string source, string message)
  12. {
  13. Publish(source, MqttTraceLevel.Information, null, message);
  14. }
  15. public static void Warning(string source, string message)
  16. {
  17. Publish(source, MqttTraceLevel.Warning, null, message);
  18. }
  19. public static void Warning(string source, Exception exception, string message)
  20. {
  21. Publish(source, MqttTraceLevel.Warning, exception, message);
  22. }
  23. public static void Error(string source, string message)
  24. {
  25. Publish(source, MqttTraceLevel.Error, null, message);
  26. }
  27. public static void Error(string source, Exception exception, string message)
  28. {
  29. Publish(source, MqttTraceLevel.Error, exception, message);
  30. }
  31. private static void Publish(string source, MqttTraceLevel traceLevel, Exception exception, string message)
  32. {
  33. var handler = TraceMessagePublished;
  34. if (handler == null)
  35. {
  36. return;
  37. }
  38. message = string.Format(message, 1);
  39. handler.Invoke(null, new MqttTraceMessagePublishedEventArgs(Environment.CurrentManagedThreadId, source, traceLevel, message, exception));
  40. }
  41. }
  42. }