Skip to content

Commit

Permalink
Swap Log Providers to MicroJson
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgedevs committed Apr 14, 2024
1 parent f539032 commit d86069d
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 135 deletions.
8 changes: 3 additions & 5 deletions Source/Meadow.Logging.LogProviders/Driver/CloudLogger.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Meadow.Cloud;
using Meadow.Foundation.Serialization;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -111,8 +111,6 @@ public async void LogEvent(int eventId, string description, Dictionary<string, o

private async Task Send<T>(string file, T item, Func<T, Task> sendFunc)
{
var serializeOptions = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };

var networkConnected = Resolver.Device.NetworkAdapters.Any(a => a.IsConnected);
var cloudConnected = Resolver.MeadowCloudService.ConnectionState == CloudConnectionState.Connected;

Expand All @@ -134,7 +132,7 @@ private async Task Send<T>(string file, T item, Func<T, Task> sendFunc)
continue;
}

var o = JsonSerializer.Deserialize<T>(line, serializeOptions);
var o = MicroJson.Deserialize<T>(line);
if (o != null)
{
await sendFunc(o);
Expand All @@ -161,7 +159,7 @@ private async Task Send<T>(string file, T item, Func<T, Task> sendFunc)
}
else
{
var json = JsonSerializer.Serialize(item, serializeOptions);
var json = MicroJson.Serialize(item);
File.AppendAllLines(file, new[] { json });
Resolver.Log.Debug($"saved cloud log to local store {json}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\Meadow.Contracts\Source\Meadow.Contracts\Meadow.Contracts.csproj" />
<ProjectReference Include="..\..\..\..\Meadow.Foundation\Source\Meadow.Foundation.Libraries_and_Frameworks\Serialization.MicroJson\Driver\Serialization.MicroJson.csproj" />
<ProjectReference Include="..\..\Meadow.Logging\lib\Meadow.Logging.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Text.Json" Version="7.0.0" />
</ItemGroup>
</Project>
Loading

0 comments on commit d86069d

Please sign in to comment.