Skip to content

Commit

Permalink
Show message when logs are empty.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Apr 12, 2021
1 parent 7377b71 commit cb3de54
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
8 changes: 8 additions & 0 deletions Agent/Services/AgentSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,14 @@ private void RegisterMessageHandlers()
{
var logBytes = await Logger.ReadAllLogs();
if (!logBytes.Any())
{
var message = "There are no log entries written.";
await _hubConnection.InvokeAsync("SendLogs", message, senderConnectionId);
return;
}
for (var i = 0; i < logBytes.Length; i += 100_000)
{
var chunk = Encoding.UTF8.GetString(logBytes.Skip(i).Take(100_000).ToArray());
Expand Down
33 changes: 18 additions & 15 deletions Server/Pages/DeviceDetails.razor
Original file line number Diff line number Diff line change
Expand Up @@ -165,26 +165,29 @@ else
</TabContent>

<TabContent Name="remote-logs">
@if (!Device.IsOnline)
{
<h5 class="text-center mt-5">Device must be online to retrieve logs.</h5>
}
else
{
@if (_logLines.Any())
<div class="py-3">
@if (!Device.IsOnline)
{
<div style="white-space: pre;">
@foreach (var line in _logLines)
{
@line
}
</div>
<h5 class="text-center mt-5">Device must be online to retrieve logs.</h5>
}
else
{
<h5 class="text-center mt-5">Loading</h5>
@if (_logLines.Any())
{
<div style="white-space: pre;">
@foreach (var line in _logLines)
{
@line
}
</div>
}
else
{
<LoadingSignal />
}
}
}

</div>

</TabContent>

Expand Down
7 changes: 5 additions & 2 deletions Shared/Utilities/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ public static async Task<byte[]> ReadAllLogs()

return await File.ReadAllBytesAsync(LogPath);
}
catch { }
catch (Exception ex)
{
Write(ex);
return Array.Empty<byte>();
}
finally
{
WriteLock.Release();
}
return Array.Empty<byte>();
}

public static void Write(string message, EventType eventType = EventType.Info, [CallerMemberName] string callerName = "")
Expand Down

0 comments on commit cb3de54

Please sign in to comment.