From 0907eadb55f59107489e3d59209cd57d6bb87778 Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Sat, 9 Sep 2017 21:50:55 +0200 Subject: [PATCH] Make string format optional if no trace listener is attached --- MQTTnet.Core/Diagnostics/MqttTrace.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/MQTTnet.Core/Diagnostics/MqttTrace.cs b/MQTTnet.Core/Diagnostics/MqttTrace.cs index 86f5b45..c6104dc 100644 --- a/MQTTnet.Core/Diagnostics/MqttTrace.cs +++ b/MQTTnet.Core/Diagnostics/MqttTrace.cs @@ -38,7 +38,14 @@ namespace MQTTnet.Core.Diagnostics private static void Publish(string source, MqttTraceLevel traceLevel, Exception exception, string message) { - TraceMessagePublished?.Invoke(null, new MqttTraceMessagePublishedEventArgs(Environment.CurrentManagedThreadId, source, traceLevel, message, exception)); + var handler = TraceMessagePublished; + if (handler == null) + { + return; + } + + message = string.Format(message, 1); + handler.Invoke(null, new MqttTraceMessagePublishedEventArgs(Environment.CurrentManagedThreadId, source, traceLevel, message, exception)); } } }