From dd447f24d2d5bb229bc9e3405c69af3e56ef297e Mon Sep 17 00:00:00 2001 From: Jan Eggers Date: Fri, 27 Oct 2017 12:29:13 +0200 Subject: [PATCH] added LogId to options and use it to create logging scope --- MQTTnet.Core/Client/IMqttClientOptions.cs | 5 +++++ MQTTnet.Core/Client/MqttClient.cs | 2 +- MQTTnet.Core/Client/MqttClientOptions.cs | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/MQTTnet.Core/Client/IMqttClientOptions.cs b/MQTTnet.Core/Client/IMqttClientOptions.cs index d2bcf9d..ae77192 100644 --- a/MQTTnet.Core/Client/IMqttClientOptions.cs +++ b/MQTTnet.Core/Client/IMqttClientOptions.cs @@ -6,6 +6,11 @@ namespace MQTTnet.Core.Client public interface IMqttClientOptions { string ClientId { get; } + + /// + /// The LogId is used to create a scope to correlate logging. If no value is provided the ClientId is used instead + /// + string LogId { get; } IMqttClientCredentials Credentials { get; } bool CleanSession { get; } MqttApplicationMessage WillMessage { get; } diff --git a/MQTTnet.Core/Client/MqttClient.cs b/MQTTnet.Core/Client/MqttClient.cs index b54288c..a52ca13 100644 --- a/MQTTnet.Core/Client/MqttClient.cs +++ b/MQTTnet.Core/Client/MqttClient.cs @@ -55,7 +55,7 @@ namespace MQTTnet.Core.Client _adapter = _communicationAdapterFactory.CreateClientMqttCommunicationAdapter(options); - _scopeHandle = _logger.BeginScope(options.ClientId); + _scopeHandle = _logger.BeginScope(options.LogId ?? options.ClientId); _logger.LogTrace("Trying to connect with server."); await _adapter.ConnectAsync(_options.CommunicationTimeout).ConfigureAwait(false); _logger.LogTrace("Connection with server established."); diff --git a/MQTTnet.Core/Client/MqttClientOptions.cs b/MQTTnet.Core/Client/MqttClientOptions.cs index 04cf8bd..1b1c1bb 100644 --- a/MQTTnet.Core/Client/MqttClientOptions.cs +++ b/MQTTnet.Core/Client/MqttClientOptions.cs @@ -9,6 +9,9 @@ namespace MQTTnet.Core.Client public string ClientId { get; set; } = Guid.NewGuid().ToString("N"); + /// + public string LogId { get; set; } + public bool CleanSession { get; set; } = true; public IMqttClientCredentials Credentials { get; set; } = new MqttClientCredentials();