25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

36 lines
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. }