Switch from Newtonsoft.Json to System.Text.Json in the logger
This commit is contained in:
parent
6f94de5a14
commit
7b06965f14
2 changed files with 9 additions and 9 deletions
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using Newtonsoft.Json;
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace Geekbot.Core.Logger
|
namespace Geekbot.Core.Logger
|
||||||
{
|
{
|
||||||
|
@ -7,16 +8,16 @@ namespace Geekbot.Core.Logger
|
||||||
{
|
{
|
||||||
private readonly bool _logAsJson;
|
private readonly bool _logAsJson;
|
||||||
private readonly NLog.Logger _logger;
|
private readonly NLog.Logger _logger;
|
||||||
private readonly JsonSerializerSettings _serializerSettings;
|
private readonly JsonSerializerOptions _serializerSettings;
|
||||||
|
|
||||||
public GeekbotLogger(RunParameters runParameters)
|
public GeekbotLogger(RunParameters runParameters)
|
||||||
{
|
{
|
||||||
_logAsJson = !string.IsNullOrEmpty(runParameters.SumologicEndpoint) || runParameters.LogJson;
|
_logAsJson = !string.IsNullOrEmpty(runParameters.SumologicEndpoint) || runParameters.LogJson;
|
||||||
_logger = LoggerFactory.CreateNLog(runParameters);
|
_logger = LoggerFactory.CreateNLog(runParameters);
|
||||||
_serializerSettings = new JsonSerializerSettings
|
_serializerSettings = new JsonSerializerOptions
|
||||||
{
|
{
|
||||||
ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
|
ReferenceHandler = ReferenceHandler.IgnoreCycles,
|
||||||
NullValueHandling = NullValueHandling.Include
|
DefaultIgnoreCondition = JsonIgnoreCondition.Never,
|
||||||
};
|
};
|
||||||
Information(LogSource.Geekbot, "Using GeekbotLogger");
|
Information(LogSource.Geekbot, "Using GeekbotLogger");
|
||||||
}
|
}
|
||||||
|
@ -53,7 +54,7 @@ namespace Geekbot.Core.Logger
|
||||||
StackTrace = stackTrace,
|
StackTrace = stackTrace,
|
||||||
Extra = extra
|
Extra = extra
|
||||||
};
|
};
|
||||||
return JsonConvert.SerializeObject(logObject, Formatting.None, _serializerSettings);
|
return JsonSerializer.Serialize(logObject, _serializerSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (source != LogSource.Message) return $"[{source}] - {message}";
|
if (source != LogSource.Message) return $"[{source}] - {message}";
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
using Newtonsoft.Json;
|
using System.Text.Json.Serialization;
|
||||||
using Newtonsoft.Json.Converters;
|
|
||||||
|
|
||||||
namespace Geekbot.Core.Logger
|
namespace Geekbot.Core.Logger
|
||||||
{
|
{
|
||||||
[JsonConverter(typeof(StringEnumConverter))]
|
[JsonConverter(typeof(JsonStringEnumConverter))]
|
||||||
public enum LogSource
|
public enum LogSource
|
||||||
{
|
{
|
||||||
Geekbot,
|
Geekbot,
|
||||||
|
|
Loading…
Reference in a new issue