Skip to content
This repository was archived by the owner on Jan 25, 2026. It is now read-only.

Commit 14b5eab

Browse files
committed
feat(LifeCycle): 加入更多的可观察日志
1 parent 7b8392b commit 14b5eab

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

LifecycleManagement/Lifecycle.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ private static void _PushLog(LifecycleLogItem item, ILifecycleLogService service
4343

4444
private static void _SavePendingLogs()
4545
{
46-
if (_PendingLogs.Count == 0) return;
46+
if (_PendingLogs.Count == 0)
47+
{
48+
Console.WriteLine("[LifeCycle] No pending logs found, returned.");
49+
return;
50+
}
4751
try
4852
{
4953
// 直接写入剩余未输出日志到程序目录
@@ -278,7 +282,12 @@ private static void _Exit(int statusCode = 0)
278282
Console.WriteLine($"[Lifecycle] Requested by '{s.Identifier}', restarting the program...");
279283
_RunCurrentExecutable(_requestRestartArguments);
280284
}
281-
Environment.Exit(statusCode);
285+
foreach (ProcessThread processThread in Process.GetCurrentProcess().Threads)
286+
{
287+
Console.WriteLine($"[LifeCycle] Thread still in working: {processThread.Id}({processThread.ThreadState})(Start from {processThread.StartTime})");
288+
}
289+
Environment.Exit(statusCode);
290+
Console.WriteLine("[LifeCycle] Warning! Abnormal behaviour, try to kill process 1s later.");
282291
// 保险起见,只要运行环境正常根本不可能执行到这里,但是永远都不能假设用户的环境是正常的
283292
Thread.Sleep(1000);
284293
Console.WriteLine("[Lifecycle] Trying to force kill the process");

Service/LogService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ public void Stop()
3535
Context.Trace("正在取消注册日志事件");
3636
LogWrapper.OnLog -= OnWrapperLog;
3737
Context.Trace("正在结束 Logger 实例");
38+
Console.WriteLine("[LifeCycle] Stopping LogService.");
3839
Logger.Dispose();
40+
Console.WriteLine("[LifeCycle] LogService has been stopped.");
3941
}
4042

4143
private void OnWrapperLog(LogLevel level, string msg, string? module, Exception? ex)

Utils/Logger/Logger.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,11 @@ private void _DoWrite(string ctx)
146146
public void Dispose()
147147
{
148148
if (_disposed) return;
149+
GC.SuppressFinalize(this);
149150
_disposed = true;
150151
_cts.Cancel();
151152
_logEvent.Set();
152-
_processingThread.Join();
153+
_processingThread.Join(5000);
153154
_logEvent.Dispose();
154155
_currentStream?.Dispose();
155156
_currentFile?.Dispose();

0 commit comments

Comments
 (0)