From 97750ec3864aa6f72866eeb92a86723098ae3fdd Mon Sep 17 00:00:00 2001 From: Dustin Updyke Date: Wed, 6 Mar 2024 10:47:08 -0500 Subject: [PATCH] adds logging --- src/Ghosts.Api/Controllers/ClientUpdatesController.cs | 6 +++--- src/Ghosts.Api/Controllers/MachineUpdatesController.cs | 2 +- .../Infrastructure/Services/MachineUpdateService.cs | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Ghosts.Api/Controllers/ClientUpdatesController.cs b/src/Ghosts.Api/Controllers/ClientUpdatesController.cs index a854687d..c39d242d 100755 --- a/src/Ghosts.Api/Controllers/ClientUpdatesController.cs +++ b/src/Ghosts.Api/Controllers/ClientUpdatesController.cs @@ -20,7 +20,7 @@ namespace Ghosts.Api.Controllers [Route("api/[controller]")] public class ClientUpdatesController : Controller { - private static readonly Logger log = LogManager.GetCurrentClassLogger(); + private static readonly Logger _log = LogManager.GetCurrentClassLogger(); private readonly IBackgroundQueue _queue; private readonly IMachineUpdateService _updateService; private readonly IMachineService _machineService; @@ -47,7 +47,7 @@ public ClientUpdatesController(IMachineService machineService, IMachineUpdateSer public async Task Index(CancellationToken ct) { var id = Request.Headers["ghosts-id"]; - log.Trace($"Request by {id}"); + _log.Trace($"Request by {id}"); var findMachineResponse = await this._machineService.FindOrCreate(HttpContext, ct); if (!findMachineResponse.IsValid()) @@ -74,7 +74,7 @@ public async Task Index(CancellationToken ct) var u = await _updateService.GetAsync(m.Id, m.CurrentUsername, ct); if (u == null) return NotFound(); - log.Trace($"Update sent to {m.Id} {m.FQDN} {u.Id} {u.Username} {u.Update}"); + _log.Trace($"Update sent to {m.Id} {m.FQDN} {u.Id} {u.Username} {u.Update}"); var update = new UpdateClientConfig { Type = u.Type, Update = u.Update }; diff --git a/src/Ghosts.Api/Controllers/MachineUpdatesController.cs b/src/Ghosts.Api/Controllers/MachineUpdatesController.cs index 304f00e8..8960eef8 100755 --- a/src/Ghosts.Api/Controllers/MachineUpdatesController.cs +++ b/src/Ghosts.Api/Controllers/MachineUpdatesController.cs @@ -21,7 +21,7 @@ namespace Ghosts.Api.Controllers [Route("api/[controller]")] public class MachineUpdatesController : Controller { - private static readonly Logger log = LogManager.GetCurrentClassLogger(); + private static readonly Logger _log = LogManager.GetCurrentClassLogger(); private readonly IBackgroundQueue _queue; private readonly IMachineUpdateService _updateService; diff --git a/src/Ghosts.Api/Infrastructure/Services/MachineUpdateService.cs b/src/Ghosts.Api/Infrastructure/Services/MachineUpdateService.cs index c387a740..7a4b9d6c 100644 --- a/src/Ghosts.Api/Infrastructure/Services/MachineUpdateService.cs +++ b/src/Ghosts.Api/Infrastructure/Services/MachineUpdateService.cs @@ -66,6 +66,8 @@ public async Task GetAsync(Guid machineId, string currentUsername var update = await _context.MachineUpdates .FirstOrDefaultAsync(m => (m.MachineId == machineId) && m.ActiveUtc < DateTime.UtcNow && m.Status == StatusType.Active, ct); + _log.Trace($"Update by machine id {machineId} is {update == null}"); + if (update != null && !string.IsNullOrEmpty(update.Update)) { // if the username is there, but the machine id is not @@ -73,6 +75,7 @@ public async Task GetAsync(Guid machineId, string currentUsername { update = await _context.MachineUpdates .FirstOrDefaultAsync(m => (m.Username.ToLower().StartsWith(currentUsername.ToLower())) && m.ActiveUtc < DateTime.UtcNow && m.Status == StatusType.Active, ct); + _log.Trace($"Update by username {currentUsername} is {update == null}"); } else // pick either { @@ -80,6 +83,7 @@ public async Task GetAsync(Guid machineId, string currentUsername .FirstOrDefaultAsync( m => (m.MachineId == machineId || m.Username.ToLower().StartsWith(currentUsername.ToLower())) && m.ActiveUtc < DateTime.UtcNow && m.Status == StatusType.Active, ct); + _log.Trace($"Update by either {machineId} or {currentUsername} is {update == null}"); } }