Renamed trace class

This commit is contained in:
Christian Kratky
2017-10-07 13:06:13 +02:00
parent d22528ca46
commit af3cebb266
19 changed files with 73 additions and 72 deletions
+2
View File
@@ -17,6 +17,8 @@
* [Server] Fixed handling of _Dup_ flag (Thanks to haeberle) * [Server] Fixed handling of _Dup_ flag (Thanks to haeberle)
* [Core] Optimized exception handling * [Core] Optimized exception handling
* [Core] Mono is now also supported (Thanks to JTrotta) * [Core] Mono is now also supported (Thanks to JTrotta)
* [Client] The options are now passed in _ConnectAsync_ (Breaking change!)
* [Core] Trace class renamed to _MqttNetTrace_ (Breaking change!)
</releaseNotes> </releaseNotes>
<copyright>Copyright Christian Kratky 2016-2017</copyright> <copyright>Copyright Christian Kratky 2016-2017</copyright>
<tags>MQTT Message Queue Telemetry Transport MQTTClient MQTTServer Server MQTTBroker Broker NETStandard IoT InternetOfThings Messaging Hardware Arduino Sensor Actuator M2M</tags> <tags>MQTT Message Queue Telemetry Transport MQTTClient MQTTServer Server MQTTBroker Broker NETStandard IoT InternetOfThings Messaging Hardware Arduino Sensor Actuator M2M</tags>
@@ -97,7 +97,7 @@ namespace MQTTnet.Implementations
} }
catch (Exception exception) when (!(exception is ObjectDisposedException)) catch (Exception exception) when (!(exception is ObjectDisposedException))
{ {
MqttTrace.Error(nameof(MqttServerAdapter), exception, "Error while accepting connection at default endpoint."); MqttNetTrace.Error(nameof(MqttServerAdapter), exception, "Error while accepting connection at default endpoint.");
//excessive CPU consumed if in endless loop of socket errors //excessive CPU consumed if in endless loop of socket errors
await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false); await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false);
@@ -122,7 +122,7 @@ namespace MQTTnet.Implementations
} }
catch (Exception exception) catch (Exception exception)
{ {
MqttTrace.Error(nameof(MqttServerAdapter), exception, "Error while accepting connection at TLS endpoint."); MqttNetTrace.Error(nameof(MqttServerAdapter), exception, "Error while accepting connection at TLS endpoint.");
//excessive CPU consumed if in endless loop of socket errors //excessive CPU consumed if in endless loop of socket errors
await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false); await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false);
@@ -56,7 +56,7 @@ namespace MQTTnet.Implementations
if (_options.TlsOptions.UseTls) if (_options.TlsOptions.UseTls)
{ {
_sslStream = new SslStream(new NetworkStream(_socket, true)); _sslStream = new SslStream(new NetworkStream(_socket, true));
await _sslStream.AuthenticateAsClientAsync(_options.Server, LoadCertificates(_options), SslProtocols.Tls12, _options.TlsOptions.CheckCertificateRevocation).ConfigureAwait(false); await _sslStream.AuthenticateAsClientAsync(_options.Server, LoadCertificates(_options), SslProtocols.Tls12, _options.TlsOptions.CheckCertificateRevocation).ConfigureAwait(false);
} }
@@ -94,7 +94,7 @@ namespace MQTTnet.Implementations
} }
catch (Exception exception) catch (Exception exception)
{ {
MqttTrace.Error(nameof(MqttServerAdapter), exception, "Error while accepting connection at default endpoint."); MqttNetTrace.Error(nameof(MqttServerAdapter), exception, "Error while accepting connection at default endpoint.");
//excessive CPU consumed if in endless loop of socket errors //excessive CPU consumed if in endless loop of socket errors
await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false); await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false);
@@ -118,7 +118,7 @@ namespace MQTTnet.Implementations
} }
catch (Exception exception) catch (Exception exception)
{ {
MqttTrace.Error(nameof(MqttServerAdapter), exception, "Error while accepting connection at TLS endpoint."); MqttNetTrace.Error(nameof(MqttServerAdapter), exception, "Error while accepting connection at TLS endpoint.");
//excessive CPU consumed if in endless loop of socket errors //excessive CPU consumed if in endless loop of socket errors
await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false); await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false);
@@ -61,7 +61,7 @@ namespace MQTTnet.Implementations
} }
catch (Exception exception) catch (Exception exception)
{ {
MqttTrace.Error(nameof(MqttServerAdapter), exception, "Error while accepting connection at default endpoint."); MqttNetTrace.Error(nameof(MqttServerAdapter), exception, "Error while accepting connection at default endpoint.");
} }
} }
} }
@@ -4,7 +4,6 @@ using System.IO;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MQTTnet.Core.Channel; using MQTTnet.Core.Channel;
using MQTTnet.Core.Client;
using MQTTnet.Core.Diagnostics; using MQTTnet.Core.Diagnostics;
using MQTTnet.Core.Exceptions; using MQTTnet.Core.Exceptions;
using MQTTnet.Core.Internal; using MQTTnet.Core.Internal;
@@ -95,7 +94,7 @@ namespace MQTTnet.Core.Adapter
continue; continue;
} }
MqttTrace.Information(nameof(MqttChannelCommunicationAdapter), "TX >>> {0} [Timeout={1}]", packet, timeout); MqttNetTrace.Information(nameof(MqttChannelCommunicationAdapter), "TX >>> {0} [Timeout={1}]", packet, timeout);
var writeBuffer = PacketSerializer.Serialize(packet); var writeBuffer = PacketSerializer.Serialize(packet);
await _channel.SendStream.WriteAsync(writeBuffer, 0, writeBuffer.Length, cancellationToken).ConfigureAwait(false); await _channel.SendStream.WriteAsync(writeBuffer, 0, writeBuffer.Length, cancellationToken).ConfigureAwait(false);
@@ -161,7 +160,7 @@ namespace MQTTnet.Core.Adapter
throw new MqttProtocolViolationException("Received malformed packet."); throw new MqttProtocolViolationException("Received malformed packet.");
} }
MqttTrace.Information(nameof(MqttChannelCommunicationAdapter), "RX <<< {0}", packet); MqttNetTrace.Information(nameof(MqttChannelCommunicationAdapter), "RX <<< {0}", packet);
return packet; return packet;
} }
catch (TaskCanceledException) catch (TaskCanceledException)
+17 -17
View File
@@ -26,7 +26,7 @@ namespace MQTTnet.Core.Client
public MqttClient(IMqttCommunicationAdapterFactory communicationChannelFactory) public MqttClient(IMqttCommunicationAdapterFactory communicationChannelFactory)
{ {
_communicationChannelFactory = communicationChannelFactory; _communicationChannelFactory = communicationChannelFactory ?? throw new ArgumentNullException(nameof(communicationChannelFactory));
} }
public event EventHandler Connected; public event EventHandler Connected;
@@ -50,14 +50,14 @@ namespace MQTTnet.Core.Client
_adapter = _communicationChannelFactory.CreateMqttCommunicationAdapter(options); _adapter = _communicationChannelFactory.CreateMqttCommunicationAdapter(options);
MqttTrace.Verbose(nameof(MqttClient), "Trying to connect with server."); MqttNetTrace.Verbose(nameof(MqttClient), "Trying to connect with server.");
await _adapter.ConnectAsync(_options.DefaultCommunicationTimeout).ConfigureAwait(false); await _adapter.ConnectAsync(_options.DefaultCommunicationTimeout).ConfigureAwait(false);
MqttTrace.Verbose(nameof(MqttClient), "Connection with server established."); MqttNetTrace.Verbose(nameof(MqttClient), "Connection with server established.");
await SetupIncomingPacketProcessingAsync(); await SetupIncomingPacketProcessingAsync();
await AuthenticateAsync(options.WillMessage); await AuthenticateAsync(options.WillMessage);
MqttTrace.Verbose(nameof(MqttClient), "MQTT connection with server established."); MqttNetTrace.Verbose(nameof(MqttClient), "MQTT connection with server established.");
if (_options.KeepAlivePeriod != TimeSpan.Zero) if (_options.KeepAlivePeriod != TimeSpan.Zero)
{ {
@@ -235,11 +235,11 @@ namespace MQTTnet.Core.Client
try try
{ {
await _adapter.DisconnectAsync(_options.DefaultCommunicationTimeout).ConfigureAwait(false); await _adapter.DisconnectAsync(_options.DefaultCommunicationTimeout).ConfigureAwait(false);
MqttTrace.Information(nameof(MqttClient), "Disconnected from adapter."); MqttNetTrace.Information(nameof(MqttClient), "Disconnected from adapter.");
} }
catch (Exception exception) catch (Exception exception)
{ {
MqttTrace.Warning(nameof(MqttClient), exception, "Error while disconnecting from adapter."); MqttNetTrace.Warning(nameof(MqttClient), exception, "Error while disconnecting from adapter.");
} }
finally finally
{ {
@@ -251,7 +251,7 @@ namespace MQTTnet.Core.Client
{ {
try try
{ {
MqttTrace.Information(nameof(MqttClient), "Received <<< {0}", packet); MqttNetTrace.Information(nameof(MqttClient), "Received <<< {0}", packet);
if (packet is MqttPingReqPacket) if (packet is MqttPingReqPacket)
{ {
@@ -281,7 +281,7 @@ namespace MQTTnet.Core.Client
} }
catch (Exception exception) catch (Exception exception)
{ {
MqttTrace.Error(nameof(MqttClient), exception, "Unhandled exception while processing received packet."); MqttNetTrace.Error(nameof(MqttClient), exception, "Unhandled exception while processing received packet.");
} }
} }
@@ -294,7 +294,7 @@ namespace MQTTnet.Core.Client
} }
catch (Exception exception) catch (Exception exception)
{ {
MqttTrace.Error(nameof(MqttClient), exception, "Unhandled exception while handling application message."); MqttNetTrace.Error(nameof(MqttClient), exception, "Unhandled exception while handling application message.");
} }
} }
@@ -358,7 +358,7 @@ namespace MQTTnet.Core.Client
private async Task SendKeepAliveMessagesAsync(CancellationToken cancellationToken) private async Task SendKeepAliveMessagesAsync(CancellationToken cancellationToken)
{ {
MqttTrace.Information(nameof(MqttClient), "Start sending keep alive packets."); MqttNetTrace.Information(nameof(MqttClient), "Start sending keep alive packets.");
try try
{ {
@@ -383,23 +383,23 @@ namespace MQTTnet.Core.Client
return; return;
} }
MqttTrace.Warning(nameof(MqttClient), exception, "MQTT communication exception while sending/receiving keep alive packets."); MqttNetTrace.Warning(nameof(MqttClient), exception, "MQTT communication exception while sending/receiving keep alive packets.");
await DisconnectInternalAsync().ConfigureAwait(false); await DisconnectInternalAsync().ConfigureAwait(false);
} }
catch (Exception exception) catch (Exception exception)
{ {
MqttTrace.Warning(nameof(MqttClient), exception, "Unhandled exception while sending/receiving keep alive packets."); MqttNetTrace.Warning(nameof(MqttClient), exception, "Unhandled exception while sending/receiving keep alive packets.");
await DisconnectInternalAsync().ConfigureAwait(false); await DisconnectInternalAsync().ConfigureAwait(false);
} }
finally finally
{ {
MqttTrace.Information(nameof(MqttClient), "Stopped sending keep alive packets."); MqttNetTrace.Information(nameof(MqttClient), "Stopped sending keep alive packets.");
} }
} }
private async Task ReceivePackets(CancellationToken cancellationToken) private async Task ReceivePackets(CancellationToken cancellationToken)
{ {
MqttTrace.Information(nameof(MqttClient), "Start receiving packets."); MqttNetTrace.Information(nameof(MqttClient), "Start receiving packets.");
try try
{ {
@@ -426,17 +426,17 @@ namespace MQTTnet.Core.Client
return; return;
} }
MqttTrace.Warning(nameof(MqttClient), exception, "MQTT communication exception while receiving packets."); MqttNetTrace.Warning(nameof(MqttClient), exception, "MQTT communication exception while receiving packets.");
await DisconnectInternalAsync().ConfigureAwait(false); await DisconnectInternalAsync().ConfigureAwait(false);
} }
catch (Exception exception) catch (Exception exception)
{ {
MqttTrace.Error(nameof(MqttClient), exception, "Unhandled exception while receiving packets."); MqttNetTrace.Error(nameof(MqttClient), exception, "Unhandled exception while receiving packets.");
await DisconnectInternalAsync().ConfigureAwait(false); await DisconnectInternalAsync().ConfigureAwait(false);
} }
finally finally
{ {
MqttTrace.Information(nameof(MqttClient), "Stopped receiving packets."); MqttNetTrace.Information(nameof(MqttClient), "Stopped receiving packets.");
} }
} }
+1 -1
View File
@@ -24,7 +24,7 @@ namespace MQTTnet.Core.Client
} }
catch (MqttCommunicationTimedOutException) catch (MqttCommunicationTimedOutException)
{ {
MqttTrace.Warning(nameof(MqttPacketDispatcher), "Timeout while waiting for packet of type '{0}'.", responseType.Name); MqttNetTrace.Warning(nameof(MqttPacketDispatcher), "Timeout while waiting for packet of type '{0}'.", responseType.Name);
throw; throw;
} }
finally finally
@@ -2,41 +2,41 @@
namespace MQTTnet.Core.Diagnostics namespace MQTTnet.Core.Diagnostics
{ {
public static class MqttTrace public static class MqttNetTrace
{ {
public static event EventHandler<MqttTraceMessagePublishedEventArgs> TraceMessagePublished; public static event EventHandler<MqttNetTraceMessagePublishedEventArgs> TraceMessagePublished;
public static void Verbose(string source, string message, params object[] parameters) public static void Verbose(string source, string message, params object[] parameters)
{ {
Publish(source, MqttTraceLevel.Verbose, null, message, parameters); Publish(source, MqttNetTraceLevel.Verbose, null, message, parameters);
} }
public static void Information(string source, string message, params object[] parameters) public static void Information(string source, string message, params object[] parameters)
{ {
Publish(source, MqttTraceLevel.Information, null, message, parameters); Publish(source, MqttNetTraceLevel.Information, null, message, parameters);
} }
public static void Warning(string source, string message, params object[] parameters) public static void Warning(string source, string message, params object[] parameters)
{ {
Publish(source, MqttTraceLevel.Warning, null, message, parameters); Publish(source, MqttNetTraceLevel.Warning, null, message, parameters);
} }
public static void Warning(string source, Exception exception, string message, params object[] parameters) public static void Warning(string source, Exception exception, string message, params object[] parameters)
{ {
Publish(source, MqttTraceLevel.Warning, exception, message, parameters); Publish(source, MqttNetTraceLevel.Warning, exception, message, parameters);
} }
public static void Error(string source, string message, params object[] parameters) public static void Error(string source, string message, params object[] parameters)
{ {
Publish(source, MqttTraceLevel.Error, null, message, parameters); Publish(source, MqttNetTraceLevel.Error, null, message, parameters);
} }
public static void Error(string source, Exception exception, string message, params object[] parameters) public static void Error(string source, Exception exception, string message, params object[] parameters)
{ {
Publish(source, MqttTraceLevel.Error, exception, message, parameters); Publish(source, MqttNetTraceLevel.Error, exception, message, parameters);
} }
private static void Publish(string source, MqttTraceLevel traceLevel, Exception exception, string message, params object[] parameters) private static void Publish(string source, MqttNetTraceLevel traceLevel, Exception exception, string message, params object[] parameters)
{ {
var handler = TraceMessagePublished; var handler = TraceMessagePublished;
if (handler == null) if (handler == null)
@@ -52,12 +52,12 @@ namespace MQTTnet.Core.Diagnostics
} }
catch (Exception formatException) catch (Exception formatException)
{ {
Error(nameof(MqttTrace), formatException, "Error while tracing message: " + message); Error(nameof(MqttNetTrace), formatException, "Error while tracing message: " + message);
return; return;
} }
} }
handler.Invoke(null, new MqttTraceMessagePublishedEventArgs(Environment.CurrentManagedThreadId, source, traceLevel, message, exception)); handler.Invoke(null, new MqttNetTraceMessagePublishedEventArgs(Environment.CurrentManagedThreadId, source, traceLevel, message, exception));
} }
} }
} }
@@ -1,6 +1,6 @@
namespace MQTTnet.Core.Diagnostics namespace MQTTnet.Core.Diagnostics
{ {
public enum MqttTraceLevel public enum MqttNetTraceLevel
{ {
Verbose, Verbose,
Information, Information,
@@ -2,9 +2,9 @@
namespace MQTTnet.Core.Diagnostics namespace MQTTnet.Core.Diagnostics
{ {
public sealed class MqttTraceMessagePublishedEventArgs : EventArgs public sealed class MqttNetTraceMessagePublishedEventArgs : EventArgs
{ {
public MqttTraceMessagePublishedEventArgs(int threadId, string source, MqttTraceLevel level, string message, Exception exception) public MqttNetTraceMessagePublishedEventArgs(int threadId, string source, MqttNetTraceLevel level, string message, Exception exception)
{ {
ThreadId = threadId; ThreadId = threadId;
Source = source; Source = source;
@@ -17,7 +17,7 @@ namespace MQTTnet.Core.Diagnostics
public string Source { get; } public string Source { get; }
public MqttTraceLevel Level { get; } public MqttNetTraceLevel Level { get; }
public string Message { get; } public string Message { get; }
@@ -50,7 +50,7 @@ namespace MQTTnet.Core.Server
} }
catch (Exception exception) catch (Exception exception)
{ {
MqttTrace.Error(nameof(MqttClientPendingMessagesQueue), exception, "Unhandled exception while sending pending publish packets."); MqttNetTrace.Error(nameof(MqttClientPendingMessagesQueue), exception, "Unhandled exception while sending pending publish packets.");
} }
} }
@@ -66,18 +66,18 @@ namespace MQTTnet.Core.Server
{ {
if (exception is MqttCommunicationTimedOutException) if (exception is MqttCommunicationTimedOutException)
{ {
MqttTrace.Warning(nameof(MqttClientPendingMessagesQueue), exception, "Sending publish packet failed due to timeout."); MqttNetTrace.Warning(nameof(MqttClientPendingMessagesQueue), exception, "Sending publish packet failed due to timeout.");
} }
else if (exception is MqttCommunicationException) else if (exception is MqttCommunicationException)
{ {
MqttTrace.Warning(nameof(MqttClientPendingMessagesQueue), exception, "Sending publish packet failed due to communication exception."); MqttNetTrace.Warning(nameof(MqttClientPendingMessagesQueue), exception, "Sending publish packet failed due to communication exception.");
} }
if (exception is OperationCanceledException) if (exception is OperationCanceledException)
{ {
} }
else else
{ {
MqttTrace.Error(nameof(MqttClientPendingMessagesQueue), exception, "Sending publish packet failed."); MqttNetTrace.Error(nameof(MqttClientPendingMessagesQueue), exception, "Sending publish packet failed.");
} }
if (packet.QualityOfServiceLevel > MqttQualityOfServiceLevel.AtMostOnce) if (packet.QualityOfServiceLevel > MqttQualityOfServiceLevel.AtMostOnce)
@@ -39,7 +39,7 @@ namespace MQTTnet.Core.Server
} }
catch (Exception exception) catch (Exception exception)
{ {
MqttTrace.Error(nameof(MqttClientRetainedMessagesManager), exception, "Unhandled exception while loading retained messages."); MqttNetTrace.Error(nameof(MqttClientRetainedMessagesManager), exception, "Unhandled exception while loading retained messages.");
} }
} }
@@ -53,12 +53,12 @@ namespace MQTTnet.Core.Server
if (publishPacket.Payload?.Any() == false) if (publishPacket.Payload?.Any() == false)
{ {
_retainedMessages.Remove(publishPacket.Topic); _retainedMessages.Remove(publishPacket.Topic);
MqttTrace.Information(nameof(MqttClientRetainedMessagesManager), "Client '{0}' cleared retained message for topic '{1}'.", clientId, publishPacket.Topic); MqttNetTrace.Information(nameof(MqttClientRetainedMessagesManager), "Client '{0}' cleared retained message for topic '{1}'.", clientId, publishPacket.Topic);
} }
else else
{ {
_retainedMessages[publishPacket.Topic] = publishPacket; _retainedMessages[publishPacket.Topic] = publishPacket;
MqttTrace.Information(nameof(MqttClientRetainedMessagesManager), "Client '{0}' updated retained message for topic '{1}'.", clientId, publishPacket.Topic); MqttNetTrace.Information(nameof(MqttClientRetainedMessagesManager), "Client '{0}' updated retained message for topic '{1}'.", clientId, publishPacket.Topic);
} }
allRetainedMessages = new List<MqttPublishPacket>(_retainedMessages.Values); allRetainedMessages = new List<MqttPublishPacket>(_retainedMessages.Values);
@@ -74,7 +74,7 @@ namespace MQTTnet.Core.Server
} }
catch (Exception exception) catch (Exception exception)
{ {
MqttTrace.Error(nameof(MqttClientRetainedMessagesManager), exception, "Unhandled exception while saving retained messages."); MqttNetTrace.Error(nameof(MqttClientRetainedMessagesManager), exception, "Unhandled exception while saving retained messages.");
} }
} }
+7 -7
View File
@@ -58,11 +58,11 @@ namespace MQTTnet.Core.Server
} }
catch (MqttCommunicationException exception) catch (MqttCommunicationException exception)
{ {
MqttTrace.Warning(nameof(MqttClientSession), exception, "Client '{0}': Communication exception while processing client packets.", ClientId); MqttNetTrace.Warning(nameof(MqttClientSession), exception, "Client '{0}': Communication exception while processing client packets.", ClientId);
} }
catch (Exception exception) catch (Exception exception)
{ {
MqttTrace.Error(nameof(MqttClientSession), exception, "Client '{0}': Unhandled exception while processing client packets.", ClientId); MqttNetTrace.Error(nameof(MqttClientSession), exception, "Client '{0}': Unhandled exception while processing client packets.", ClientId);
} }
} }
@@ -79,7 +79,7 @@ namespace MQTTnet.Core.Server
_adapter = null; _adapter = null;
MqttTrace.Information(nameof(MqttClientSession), "Client '{0}': Disconnected.", ClientId); MqttNetTrace.Information(nameof(MqttClientSession), "Client '{0}': Disconnected.", ClientId);
} }
public void EnqueuePublishPacket(MqttPublishPacket publishPacket) public void EnqueuePublishPacket(MqttPublishPacket publishPacket)
@@ -92,7 +92,7 @@ namespace MQTTnet.Core.Server
} }
_pendingMessagesQueue.Enqueue(publishPacket); _pendingMessagesQueue.Enqueue(publishPacket);
MqttTrace.Verbose(nameof(MqttClientSession), "Client '{0}': Enqueued pending publish packet.", ClientId); MqttNetTrace.Verbose(nameof(MqttClientSession), "Client '{0}': Enqueued pending publish packet.", ClientId);
} }
public void Dispose() public void Dispose()
@@ -116,12 +116,12 @@ namespace MQTTnet.Core.Server
} }
catch (MqttCommunicationException exception) catch (MqttCommunicationException exception)
{ {
MqttTrace.Warning(nameof(MqttClientSession), exception, "Client '{0}': Communication exception while processing client packets.", ClientId); MqttNetTrace.Warning(nameof(MqttClientSession), exception, "Client '{0}': Communication exception while processing client packets.", ClientId);
Stop(); Stop();
} }
catch (Exception exception) catch (Exception exception)
{ {
MqttTrace.Error(nameof(MqttClientSession), exception, "Client '{0}': Unhandled exception while processing client packets.", ClientId); MqttNetTrace.Error(nameof(MqttClientSession), exception, "Client '{0}': Unhandled exception while processing client packets.", ClientId);
Stop(); Stop();
} }
} }
@@ -163,7 +163,7 @@ namespace MQTTnet.Core.Server
} }
else else
{ {
MqttTrace.Warning(nameof(MqttClientSession), "Client '{0}': Received not supported packet ({1}). Closing connection.", ClientId, packet); MqttNetTrace.Warning(nameof(MqttClientSession), "Client '{0}': Received not supported packet ({1}). Closing connection.", ClientId, packet);
Stop(); Stop();
} }
} }
@@ -74,7 +74,7 @@ namespace MQTTnet.Core.Server
} }
catch (Exception exception) catch (Exception exception)
{ {
MqttTrace.Error(nameof(MqttServer), exception, exception.Message); MqttNetTrace.Error(nameof(MqttServer), exception, exception.Message);
} }
finally finally
{ {
@@ -124,7 +124,7 @@ namespace MQTTnet.Core.Server
} }
catch (Exception exception) catch (Exception exception)
{ {
MqttTrace.Error(nameof(MqttClientSessionsManager), exception, "Error while processing application message"); MqttNetTrace.Error(nameof(MqttClientSessionsManager), exception, "Error while processing application message");
} }
lock (_clientSessions) lock (_clientSessions)
@@ -158,11 +158,11 @@ namespace MQTTnet.Core.Server
_clientSessions.Remove(connectPacket.ClientId); _clientSessions.Remove(connectPacket.ClientId);
clientSession.Dispose(); clientSession.Dispose();
clientSession = null; clientSession = null;
MqttTrace.Verbose(nameof(MqttClientSessionsManager), "Disposed existing session of client '{0}'.", connectPacket.ClientId); MqttNetTrace.Verbose(nameof(MqttClientSessionsManager), "Disposed existing session of client '{0}'.", connectPacket.ClientId);
} }
else else
{ {
MqttTrace.Verbose(nameof(MqttClientSessionsManager), "Reusing existing session of client '{0}'.", connectPacket.ClientId); MqttNetTrace.Verbose(nameof(MqttClientSessionsManager), "Reusing existing session of client '{0}'.", connectPacket.ClientId);
} }
} }
@@ -174,7 +174,7 @@ namespace MQTTnet.Core.Server
clientSession = new MqttClientSession(connectPacket.ClientId, _options, this); clientSession = new MqttClientSession(connectPacket.ClientId, _options, this);
_clientSessions[connectPacket.ClientId] = clientSession; _clientSessions[connectPacket.ClientId] = clientSession;
MqttTrace.Verbose(nameof(MqttClientSessionsManager), "Created a new session for client '{0}'.", connectPacket.ClientId); MqttNetTrace.Verbose(nameof(MqttClientSessionsManager), "Created a new session for client '{0}'.", connectPacket.ClientId);
} }
return new GetOrCreateClientSessionResult { IsExistingSession = isExistingSession, Session = clientSession }; return new GetOrCreateClientSessionResult { IsExistingSession = isExistingSession, Session = clientSession };
+4 -4
View File
@@ -57,7 +57,7 @@ namespace MQTTnet.Core.Server
await adapter.StartAsync(_options); await adapter.StartAsync(_options);
} }
MqttTrace.Information(nameof(MqttServer), "Started."); MqttNetTrace.Information(nameof(MqttServer), "Started.");
} }
public async Task StopAsync() public async Task StopAsync()
@@ -74,7 +74,7 @@ namespace MQTTnet.Core.Server
_clientSessionsManager.Clear(); _clientSessionsManager.Clear();
MqttTrace.Information(nameof(MqttServer), "Stopped."); MqttNetTrace.Information(nameof(MqttServer), "Stopped.");
} }
private void OnClientAccepted(IMqttCommunicationAdapter adapter) private void OnClientAccepted(IMqttCommunicationAdapter adapter)
@@ -84,13 +84,13 @@ namespace MQTTnet.Core.Server
private void OnClientConnected(object sender, MqttClientConnectedEventArgs eventArgs) private void OnClientConnected(object sender, MqttClientConnectedEventArgs eventArgs)
{ {
MqttTrace.Information(nameof(MqttServer), "Client '{0}': Connected.", eventArgs.Client.ClientId); MqttNetTrace.Information(nameof(MqttServer), "Client '{0}': Connected.", eventArgs.Client.ClientId);
ClientConnected?.Invoke(this, eventArgs); ClientConnected?.Invoke(this, eventArgs);
} }
private void OnClientDisconnected(object sender, MqttClientDisconnectedEventArgs eventArgs) private void OnClientDisconnected(object sender, MqttClientDisconnectedEventArgs eventArgs)
{ {
MqttTrace.Information(nameof(MqttServer), "Client '{0}': Disconnected.", eventArgs.Client.ClientId); MqttNetTrace.Information(nameof(MqttServer), "Client '{0}': Disconnected.", eventArgs.Client.ClientId);
ClientDisconnected?.Invoke(this, eventArgs); ClientDisconnected?.Invoke(this, eventArgs);
} }
} }
+2 -2
View File
@@ -35,7 +35,7 @@ namespace MQTTnet.TestApp.NetCore
private static async Task RunClientAsync(string[] arguments) private static async Task RunClientAsync(string[] arguments)
{ {
MqttTrace.TraceMessagePublished += (s, e) => MqttNetTrace.TraceMessagePublished += (s, e) =>
{ {
Console.WriteLine($">> [{e.ThreadId}] [{e.Source}] [{e.Level}]: {e.Message}"); Console.WriteLine($">> [{e.ThreadId}] [{e.Source}] [{e.Level}]: {e.Message}");
if (e.Exception != null) if (e.Exception != null)
@@ -124,7 +124,7 @@ namespace MQTTnet.TestApp.NetCore
private static void RunServerAsync(string[] arguments) private static void RunServerAsync(string[] arguments)
{ {
MqttTrace.TraceMessagePublished += (s, e) => MqttNetTrace.TraceMessagePublished += (s, e) =>
{ {
Console.WriteLine($">> [{e.ThreadId}] [{e.Source}] [{e.Level}]: {e.Message}"); Console.WriteLine($">> [{e.ThreadId}] [{e.Source}] [{e.Level}]: {e.Message}");
if (e.Exception != null) if (e.Exception != null)
@@ -41,7 +41,7 @@ namespace MQTTnet.TestApp.NetFramework
private static async Task RunClientAsync(string[] arguments) private static async Task RunClientAsync(string[] arguments)
{ {
MqttTrace.TraceMessagePublished += (s, e) => MqttNetTrace.TraceMessagePublished += (s, e) =>
{ {
Console.WriteLine($">> [{e.ThreadId}] [{e.Source}] [{e.Level}]: {e.Message}"); Console.WriteLine($">> [{e.ThreadId}] [{e.Source}] [{e.Level}]: {e.Message}");
if (e.Exception != null) if (e.Exception != null)
@@ -128,7 +128,7 @@ namespace MQTTnet.TestApp.NetFramework
private static async Task RunServerAsync(string[] arguments) private static async Task RunServerAsync(string[] arguments)
{ {
MqttTrace.TraceMessagePublished += (s, e) => MqttNetTrace.TraceMessagePublished += (s, e) =>
{ {
Console.WriteLine($">> [{e.ThreadId}] [{e.Source}] [{e.Level}]: {e.Message}"); Console.WriteLine($">> [{e.ThreadId}] [{e.Source}] [{e.Level}]: {e.Message}");
if (e.Exception != null) if (e.Exception != null)
@@ -18,10 +18,10 @@ namespace MQTTnet.TestApp.UniversalWindows
{ {
InitializeComponent(); InitializeComponent();
MqttTrace.TraceMessagePublished += OnTraceMessagePublished; MqttNetTrace.TraceMessagePublished += OnTraceMessagePublished;
} }
private async void OnTraceMessagePublished(object sender, MqttTraceMessagePublishedEventArgs e) private async void OnTraceMessagePublished(object sender, MqttNetTraceMessagePublishedEventArgs e)
{ {
await Trace.Dispatcher.RunAsync(CoreDispatcherPriority.High, () => await Trace.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
{ {