소스 검색

Add MQTTnet debug logging.

release/3.x.x
Christian Kratky 5 년 전
부모
커밋
653ea8a102
6개의 변경된 파일33개의 추가작업 그리고 13개의 파일을 삭제
  1. +2
    -0
      Source/MQTTnet.Server/Configuration/SettingsModel.cs
  2. +1
    -7
      Source/MQTTnet.Server/Logging/MqttNetLoggerWrapper.cs
  3. +3
    -0
      Source/MQTTnet.Server/MQTTnet.Server.csproj
  4. +19
    -3
      Source/MQTTnet.Server/Mqtt/CustomMqttFactory.cs
  5. +2
    -0
      Source/MQTTnet.Server/Run.bat
  6. +6
    -3
      Source/MQTTnet.Server/appsettings.json

+ 2
- 0
Source/MQTTnet.Server/Configuration/SettingsModel.cs 파일 보기

@@ -44,5 +44,7 @@
/// The settings for retained messages.
/// </summary>
public RetainedApplicationMessagesModel RetainedApplicationMessages { get; set; } = new RetainedApplicationMessagesModel();

public bool EnableDebugLogging { get; set; } = false;
}
}

+ 1
- 7
Source/MQTTnet.Server/Logging/MqttNetLoggerWrapper.cs 파일 보기

@@ -23,12 +23,6 @@ namespace MQTTnet.Server.Logging
public void Publish(MqttNetLogLevel logLevel, string source, string message, object[] parameters, Exception exception)
{
var convertedLogLevel = ConvertLogLevel(logLevel);

if (!_logger.IsEnabled(convertedLogLevel))
{
return;
}

_logger.Log(convertedLogLevel, exception, message, parameters);
}

@@ -39,7 +33,7 @@ namespace MQTTnet.Server.Logging
case MqttNetLogLevel.Error: return LogLevel.Error;
case MqttNetLogLevel.Warning: return LogLevel.Warning;
case MqttNetLogLevel.Info: return LogLevel.Information;
case MqttNetLogLevel.Verbose: return LogLevel.Trace;
case MqttNetLogLevel.Verbose: return LogLevel.Debug;
}

return LogLevel.Debug;


+ 3
- 0
Source/MQTTnet.Server/MQTTnet.Server.csproj 파일 보기

@@ -66,6 +66,9 @@
<None Update="LICENSE">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Run.bat">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Scripts\readme.md">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>


+ 19
- 3
Source/MQTTnet.Server/Mqtt/CustomMqttFactory.cs 파일 보기

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using Microsoft.Extensions.Logging;
using MQTTnet.Adapter;
using MQTTnet.Diagnostics;
using MQTTnet.Server.Configuration;
using MQTTnet.Server.Logging;

namespace MQTTnet.Server.Mqtt
@@ -11,13 +12,28 @@ namespace MQTTnet.Server.Mqtt
{
private readonly MqttFactory _mqttFactory;

public CustomMqttFactory(ILogger<MqttServer> logger)
public CustomMqttFactory(SettingsModel settings, ILogger<MqttServer> logger)
{
if (settings == null) throw new ArgumentNullException(nameof(settings));
if (logger == null) throw new ArgumentNullException(nameof(logger));
// It is important to avoid injecting the logger wrapper to ensure that no
// unused log messages are generated by the MQTTnet library. Debug logging
// has a huge performance impact.
if (settings.EnableDebugLogging)
{
var mqttNetLogger = new MqttNetLoggerWrapper(logger);
_mqttFactory = new MqttFactory(mqttNetLogger);

Logger = new MqttNetLoggerWrapper(logger);
logger.LogWarning("Debug logging is enabled. Performance of MQTTnet Server is decreased!");
}
else
{
_mqttFactory = new MqttFactory();
}

Logger = _mqttFactory.DefaultLogger;

_mqttFactory = new MqttFactory(Logger);
}
public IMqttNetLogger Logger { get; }


+ 2
- 0
Source/MQTTnet.Server/Run.bat 파일 보기

@@ -0,0 +1,2 @@
@echo off
START "MQTTnet Server" dotnet .\MQTTnet.Server.dll

+ 6
- 3
Source/MQTTnet.Server/appsettings.json 파일 보기

@@ -43,12 +43,15 @@
"RetainedApplicationMessages": {
"Persist": true,
"Filename": "RetainedApplicationMessages.json",
"WriteInterval": 10 // In seconds.
}
"WriteInterval": 10 // In seconds.
},
"EnableDebugLogging": false
},
"Logging": {
"LogLevel": {
"Default": "Warning"
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"AllowedHosts": "*"


불러오는 중...
취소
저장