using System; using System.Collections.Concurrent; using Microsoft.Extensions.Logging; namespace MQTTnet.Core.Diagnostics { public class MqttNetTrace : ILoggerProvider { private readonly ConcurrentDictionary _loggers = new ConcurrentDictionary(); public static event EventHandler TraceMessagePublished; public void Publish(MqttNetTraceMessage msg) { TraceMessagePublished?.Invoke(this, new MqttNetTraceMessagePublishedEventArgs(msg)); } public void Dispose() { TraceMessagePublished = null; } public ILogger CreateLogger(string categoryName) { return _loggers.GetOrAdd(categoryName, CreateLoggerImplementation); } private MqttNetLogger CreateLoggerImplementation(string categoryName) { return new MqttNetLogger(categoryName, this); } } }