Skip to content

Commit

Permalink
COREX-611 - LLM Suggestions (#12)
Browse files Browse the repository at this point in the history
* COREX-611 - LLM Suggestions

Added EndpointConverter to JsonSerializerSettings to customize serialization of Sysmte.Net.IPEndPoint

* Fix namespace change for tests
  • Loading branch information
elindanielsson authored Jun 24, 2024
1 parent 4c5ebbf commit a0e7c89
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 21 deletions.
19 changes: 0 additions & 19 deletions src/Logging/Loggly/Loggly/JsonSettings.cs

This file was deleted.

1 change: 1 addition & 0 deletions src/Logging/Loggly/Loggly/LogglyOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using EMG.Extensions.Logging.Loggly.SerializerSettings;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

Expand Down
29 changes: 29 additions & 0 deletions src/Logging/Loggly/Loggly/SerializerSettings/EndpointConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Newtonsoft.Json;
using System;

namespace EMG.Extensions.Logging.Loggly.SerializerSettings;

public class EndpointConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return objectType == typeof(System.Net.IPEndPoint);
}

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
if (value is System.Net.IPEndPoint endpoint)
{
writer.WriteValue(endpoint.ToString());
}
else
{
writer.WriteValue(value);
}
}

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Newtonsoft.Json;
using System;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace EMG.Extensions.Logging.Loggly.SerializerSettings;

public class FormattedIdConverter : JsonConverter
{
Expand Down
18 changes: 18 additions & 0 deletions src/Logging/Loggly/Loggly/SerializerSettings/JsonSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Newtonsoft.Json;

namespace EMG.Extensions.Logging.Loggly.SerializerSettings;

public static class JsonSettings
{
public static readonly JsonSerializerSettings SerializerSettings = new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.None,
NullValueHandling = NullValueHandling.Ignore,
Formatting = Formatting.None,
DefaultValueHandling = DefaultValueHandling.Include,
DateTimeZoneHandling = DateTimeZoneHandling.Utc,
DateFormatHandling = DateFormatHandling.IsoDateFormat,
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
Converters = { new FormattedIdConverter(), new EndpointConverter() }
};
}
1 change: 1 addition & 0 deletions tests/Logging/Tests.Loggly/FormattedIdConverterTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using EMG.Extensions.Logging.Loggly.SerializerSettings;
using NUnit.Framework;
using Newtonsoft.Json;
using Moq;
Expand Down

0 comments on commit a0e7c89

Please sign in to comment.