Skip to content

Commit

Permalink
Add-Logs-to-Hub
Browse files Browse the repository at this point in the history
  • Loading branch information
kamiljanek committed Jul 15, 2024
1 parent e72f316 commit 705f879
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions API/src/TibiaStalker.Infrastructure/Hubs/CharactersTrackHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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);
}
Expand All @@ -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);
}

/// <summary>
Expand All @@ -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()
Expand Down

0 comments on commit 705f879

Please sign in to comment.