diff --git a/MQTTnet.Core/Client/IMqttClientOptions.cs b/MQTTnet.Core/Client/IMqttClientOptions.cs
index d2bcf9d3..ae771922 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 b54288c7..a52ca13f 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 04cf8bdb..1b1c1bb8 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();