Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

36 rader
1.1 KiB

  1. using System;
  2. using System.Collections.Concurrent;
  3. using Microsoft.Extensions.Logging;
  4. namespace MQTTnet.Core.Diagnostics
  5. {
  6. public class MqttNetTrace : ILoggerProvider
  7. {
  8. private readonly ConcurrentDictionary<string, MqttNetLogger> _loggers = new ConcurrentDictionary<string, MqttNetLogger>();
  9. public static event EventHandler<MqttNetTraceMessagePublishedEventArgs> TraceMessagePublished;
  10. public static bool HasListeners => TraceMessagePublished != null;
  11. public void Publish(MqttNetTraceMessage traceMessage)
  12. {
  13. TraceMessagePublished?.Invoke(this, new MqttNetTraceMessagePublishedEventArgs(traceMessage));
  14. }
  15. public void Dispose()
  16. {
  17. TraceMessagePublished = null;
  18. }
  19. public ILogger CreateLogger(string categoryName)
  20. {
  21. return _loggers.GetOrAdd(categoryName, CreateLoggerImplementation);
  22. }
  23. private MqttNetLogger CreateLoggerImplementation(string categoryName)
  24. {
  25. return new MqttNetLogger(categoryName, this);
  26. }
  27. }
  28. }