From 705f8798e41223bc0ec6b80bc88f8fa4f6e4df32 Mon Sep 17 00:00:00 2001 From: kamiljanek <95696684+kamiljanek@users.noreply.github.com> Date: Mon, 15 Jul 2024 22:20:40 +0200 Subject: [PATCH] Add-Logs-to-Hub --- .../Hubs/CharactersTrackHub.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/API/src/TibiaStalker.Infrastructure/Hubs/CharactersTrackHub.cs b/API/src/TibiaStalker.Infrastructure/Hubs/CharactersTrackHub.cs index e8649aa..9a85c52 100644 --- a/API/src/TibiaStalker.Infrastructure/Hubs/CharactersTrackHub.cs +++ b/API/src/TibiaStalker.Infrastructure/Hubs/CharactersTrackHub.cs @@ -20,7 +20,7 @@ public override async Task OnConnectedAsync() { var realUserIp = GetRealUserIp(); - _logger.LogInformation("Client connected. ConnectionId: {ConnectionId}. UserId: {UserId}", Context.ConnectionId, realUserIp); + _logger.LogInformation("Client connected - UserId: {UserId}. ConnectionId: {ConnectionId}. ", realUserIp, Context.ConnectionId); await base.OnConnectedAsync(); } @@ -31,8 +31,8 @@ public override async Task OnDisconnectedAsync(Exception exception) var realUserIp = GetRealUserIp(); - _logger.LogInformation("Client disconnected. ConnectionId: {ConnectionId}. UserId: {UserId}, Exception: {Exception}", - Context.ConnectionId, realUserIp, exception?.ToString()); + _logger.LogInformation("Client disconnected - UserId: {UserId}. ConnectionId: {ConnectionId}. Exception: {Exception}", + realUserIp, Context.ConnectionId, exception?.ToString()); await base.OnDisconnectedAsync(exception); } @@ -47,6 +47,11 @@ public async Task JoinGroup(string groupName) await _trackCharacterService.CreateTrack(groupName, Context.ConnectionId); await Groups.AddToGroupAsync(Context.ConnectionId, groupName); + + var realUserIp = GetRealUserIp(); + + _logger.LogInformation("UserId: {UserId} - joined group: {groupName}. ConnectionId: {ConnectionId}.", + realUserIp, groupName, Context.ConnectionId); } /// @@ -59,6 +64,11 @@ public async Task LeaveGroup(string groupName) await _trackCharacterService.RemoveTrack(groupName, Context.ConnectionId); await Groups.RemoveFromGroupAsync(Context.ConnectionId, groupName); + + var realUserIp = GetRealUserIp(); + + _logger.LogInformation("UserId: {UserId} - leaved group: {groupName}. ConnectionId: {ConnectionId}.", + realUserIp, groupName, Context.ConnectionId); } private string GetRealUserIp()