Skip to content

Commit 5b572a8

Browse files
committed
Improve tracing and error logging in update strategies
Added detailed tracing and error logging to LinuxStrategy, WindowsStrategy, and bootstrap classes in both ClientCore and Core projects. Enhanced multi-download event handlers with trace messages and standardized exception logging for better diagnostics and maintainability.
1 parent 303bc1c commit 5b572a8

File tree

5 files changed

+34
-10
lines changed

5 files changed

+34
-10
lines changed

src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ private void CallSmallBowlHome(string processName)
375375
}
376376
catch (Exception ex)
377377
{
378+
GeneralTracer.Error("The CallSmallBowlHome method in the GeneralClientBootstrap class throws an exception.", ex);
378379
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(ex, ex.Message));
379380
}
380381
}
@@ -393,6 +394,7 @@ private void ExecuteCustomOptions()
393394
{
394395
var exception = new Exception($"{nameof(option)}Execution failure!");
395396
var args = new ExceptionEventArgs(exception, exception.Message);
397+
GeneralTracer.Error("The ExecuteCustomOptions method in the GeneralClientBootstrap class throws an exception.", exception);
396398
EventManager.Instance.Dispatch(this, args);
397399
}
398400
}
@@ -423,16 +425,34 @@ private GeneralClientBootstrap AddListener<TArgs>(Action<object, TArgs> callback
423425
}
424426

425427
private void OnMultiDownloadStatistics(object sender, MultiDownloadStatisticsEventArgs e)
426-
=> EventManager.Instance.Dispatch(sender, e);
428+
{
429+
var message = GetPacketHash(e.Version);
430+
GeneralTracer.Info($"Multi download statistics, {message}[BytesReceived]:{e.BytesReceived} [ProgressPercentage]:{e.ProgressPercentage} [Remaining]:{e.Remaining} [TotalBytesToReceive]:{e.TotalBytesToReceive} [Speed]:{e.Speed}");
431+
EventManager.Instance.Dispatch(sender, e);
432+
}
427433

428434
private void OnMultiDownloadCompleted(object sender, MultiDownloadCompletedEventArgs e)
429-
=> EventManager.Instance.Dispatch(sender, e);
435+
{
436+
var message = GetPacketHash(e.Version);
437+
GeneralTracer.Info($"Multi download completed, {message}[IsComplated]:{e.IsComplated}.");
438+
EventManager.Instance.Dispatch(sender, e);
439+
}
430440

431441
private void OnMultiDownloadError(object sender, MultiDownloadErrorEventArgs e)
432-
=> EventManager.Instance.Dispatch(sender, e);
442+
{
443+
var message = GetPacketHash(e.Version);
444+
GeneralTracer.Error($"Multi download error {message}.", e.Exception);
445+
EventManager.Instance.Dispatch(sender, e);
446+
}
433447

434448
private void OnMultiAllDownloadCompleted(object sender, MultiAllDownloadCompletedEventArgs e)
435-
=> EventManager.Instance.Dispatch(sender, e);
449+
{
450+
GeneralTracer.Info($"Multi all download completed {e.IsAllDownloadCompleted}.");
451+
EventManager.Instance.Dispatch(sender, e);
452+
}
453+
454+
private string GetPacketHash(object version) =>
455+
!GeneralTracer.IsTracingEnabled() ? string.Empty : $"[PacketHash]:{(version as VersionInfo).Hash} ";
436456

437457
#endregion Private Methods
438458
}

src/c#/GeneralUpdate.ClientCore/Strategys/LinuxStrategy.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public override async Task ExecuteAsync()
6262
catch (Exception e)
6363
{
6464
status = ReportType.Failure;
65+
GeneralTracer.Error("The ExecuteAsync method in the GeneralUpdate.ClientCore.LinuxStrategy class throws an exception.", e);
6566
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message));
6667
}
6768
finally
@@ -85,7 +86,7 @@ await VersionService.Report(_configinfo.ReportUrl
8586
}
8687
catch (Exception e)
8788
{
88-
GeneralTracer.Error("The ExecuteAsync method in the LinuxStrategy class throws an exception." , e);
89+
GeneralTracer.Error("The ExecuteAsync method in the GeneralUpdate.ClientCore.LinuxStrategy class throws an exception." , e);
8990
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message));
9091
}
9192
}
@@ -109,7 +110,7 @@ public override void StartApp()
109110
}
110111
catch (Exception e)
111112
{
112-
GeneralTracer.Error("The StartApp method in the LinuxStrategy class throws an exception." , e);
113+
GeneralTracer.Error("The StartApp method in the GeneralUpdate.ClientCore.LinuxStrategy class throws an exception." , e);
113114
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message));
114115
}
115116
finally

src/c#/GeneralUpdate.ClientCore/Strategys/WindowsStrategy.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public override async Task ExecuteAsync()
5858
catch (Exception e)
5959
{
6060
status = ReportType.Failure;
61+
GeneralTracer.Error("The ExecuteAsync method in the GeneralUpdate.ClientCore.WindowsStrategy class throws an exception.", e);
6162
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message));
6263
}
6364
finally
@@ -81,7 +82,7 @@ await VersionService.Report(_configinfo.ReportUrl
8182
}
8283
catch (Exception e)
8384
{
84-
GeneralTracer.Error("The ExecuteAsync method in the WindowsStrategy class throws an exception." , e);
85+
GeneralTracer.Error("The ExecuteAsync method in the GeneralUpdate.ClientCore.WindowsStrategy class throws an exception." , e);
8586
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message));
8687
}
8788
}
@@ -104,7 +105,7 @@ public override void StartApp()
104105
}
105106
catch (Exception e)
106107
{
107-
GeneralTracer.Error("The StartApp method in the WindowsStrategy class throws an exception." , e);
108+
GeneralTracer.Error("The StartApp method in the GeneralUpdate.ClientCore.WindowsStrategy class throws an exception." , e);
108109
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message));
109110
}
110111
finally

src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ private void OnMultiDownloadError(object sender, MultiDownloadErrorEventArgs e)
150150

151151
private void OnMultiAllDownloadCompleted(object sender, MultiAllDownloadCompletedEventArgs e)
152152
{
153+
GeneralTracer.Info($"Multi all download completed {e.IsAllDownloadCompleted}.");
153154
EventManager.Instance.Dispatch(sender, e);
154155
ExecuteStrategy();
155156
}

src/c#/GeneralUpdate.Core/Strategys/WindowsStrategy.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public override void Execute()
6767
catch (Exception e)
6868
{
6969
status = ReportType.Failure;
70+
GeneralTracer.Error("The Execute method in the GeneralUpdate.Core.WindowsStrategy class throws an exception.", e);
7071
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message));
7172
}
7273
finally
@@ -91,7 +92,7 @@ await VersionService.Report(_configinfo.ReportUrl
9192
}
9293
catch (Exception e)
9394
{
94-
GeneralTracer.Error("The Execute method in the WindowsStrategy class throws an exception.", e);
95+
GeneralTracer.Error("The Execute method in the GeneralUpdate.Core.WindowsStrategy class throws an exception.", e);
9596
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message));
9697
}
9798
});
@@ -116,7 +117,7 @@ public override void StartApp()
116117
}
117118
catch (Exception e)
118119
{
119-
GeneralTracer.Error("The StartApp method in the WindowsStrategy class throws an exception.", e);
120+
GeneralTracer.Error("The StartApp method in the GeneralUpdate.Core.WindowsStrategy class throws an exception.", e);
120121
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message));
121122
}
122123
finally

0 commit comments

Comments
 (0)