mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-04 08:36:11 +02:00
feat: Add diagnostic hooks and heartbeat logging for application lifecycle events
This commit is contained in:
@@ -183,9 +183,32 @@ while (true)
|
|||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
app.MapHub<ChatHub>(HubConstants.ChatHubPath);
|
app.MapHub<ChatHub>(HubConstants.ChatHubPath);
|
||||||
|
|
||||||
Console.Error.WriteLine("[DIAG] Calling app.RunAsync()...");
|
// ── Diagnostic hooks ────────────────────────────────────────────────
|
||||||
await app.RunAsync();
|
app.Lifetime.ApplicationStarted.Register(
|
||||||
Console.Error.WriteLine("[DIAG] app.RunAsync() returned.");
|
() => Console.Error.WriteLine("[DIAG] ApplicationStarted fired"));
|
||||||
|
app.Lifetime.ApplicationStopping.Register(
|
||||||
|
() => Console.Error.WriteLine("[DIAG] ApplicationStopping fired"));
|
||||||
|
app.Lifetime.ApplicationStopped.Register(
|
||||||
|
() => Console.Error.WriteLine("[DIAG] ApplicationStopped fired"));
|
||||||
|
|
||||||
|
// Heartbeat — proves the process is alive even if nothing else logs
|
||||||
|
var heartbeatCts = new CancellationTokenSource();
|
||||||
|
_ = Task.Run(async () =>
|
||||||
|
{
|
||||||
|
while (!heartbeatCts.Token.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
await Task.Delay(5000, heartbeatCts.Token).ConfigureAwait(false);
|
||||||
|
Console.Error.WriteLine($"[DIAG] heartbeat {DateTimeOffset.UtcNow:HH:mm:ss}");
|
||||||
|
}
|
||||||
|
}, heartbeatCts.Token);
|
||||||
|
|
||||||
|
Console.Error.WriteLine("[DIAG] Calling app.StartAsync()...");
|
||||||
|
await app.StartAsync();
|
||||||
|
Console.Error.WriteLine("[DIAG] app.StartAsync() completed — server is running.");
|
||||||
|
|
||||||
|
await app.WaitForShutdownAsync();
|
||||||
|
Console.Error.WriteLine("[DIAG] WaitForShutdownAsync returned.");
|
||||||
|
heartbeatCts.Cancel();
|
||||||
|
|
||||||
// Graceful shutdown (Ctrl+C) — exit the loop
|
// Graceful shutdown (Ctrl+C) — exit the loop
|
||||||
Log.Information("Server shut down gracefully");
|
Log.Information("Server shut down gracefully");
|
||||||
|
|||||||
Reference in New Issue
Block a user