Skip to content

Commit 4e16fda

Browse files
committed
Add log events for SignalR connection established and lost
1 parent f26cc38 commit 4e16fda

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Hubs/AssistantHub.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,36 @@ public class AssistantHub(FimDbContext dbContext, FimRepository repository, Assi
1717

1818
public override async Task OnConnectedAsync()
1919
{
20+
var log = new EquipmentLog
21+
{
22+
EquipmentId = CartId,
23+
LogMessage = "Admin SignalR Connection Established",
24+
Category = "General",
25+
Severity = LogSeverity.Info,
26+
ExtraInfo = null
27+
};
28+
await dbContext.EquipmentLogs.AddAsync(log);
29+
await dbContext.SaveChangesAsync();
2030
await repository.SetCartLastSeen(CartId, DateTime.MaxValue);
2131
await SendPendingAlertsToCaller();
2232
}
2333

2434
public override async Task OnDisconnectedAsync(Exception? exception)
2535
{
36+
var log = new EquipmentLog
37+
{
38+
EquipmentId = CartId,
39+
LogMessage = "Admin SignalR Connection Lost",
40+
Category = "General",
41+
Severity = LogSeverity.Info,
42+
ExtraInfo = JsonSerializer.SerializeToElement(new
43+
{
44+
Exception = exception?.ToString()
45+
})
46+
};
47+
await dbContext.EquipmentLogs.AddAsync(log);
48+
await dbContext.SaveChangesAsync();
49+
2650
await repository.SetCartLastSeen(CartId, DateTime.UtcNow);
2751
}
2852

0 commit comments

Comments
 (0)