Skip to content

Commit e5ce29d

Browse files
committed
Replace Debug.WriteLine with GeneralTracer for logging
Replaced all usages of Debug.WriteLine and Trace.WriteLine with GeneralTracer logging methods across multiple files for improved and consistent tracing. Updated project files to include GeneralTracer, and refactored exception handling to use GeneralTracer for error reporting. This change standardizes logging and error tracing throughout the codebase.
1 parent 89bec22 commit e5ce29d

File tree

20 files changed

+72
-84
lines changed

20 files changed

+72
-84
lines changed

src/c#/GeneralUpdate.Bowl/GeneralUpdate.Bowl.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<Compile Include="..\GeneralUpdate.Common\Internal\Pipeline\PipelineContext.cs" Link="Common\PipelineContext.cs" />
7272
<Compile Include="..\GeneralUpdate.Common\Internal\Strategy\AbstractStrategy.cs" Link="Common\AbstractStrategy.cs" />
7373
<Compile Include="..\GeneralUpdate.Common\Internal\Strategy\IStrategy.cs" Link="Common\IStrategy.cs" />
74+
<Compile Include="..\GeneralUpdate.Common\Internal\Trace\GeneralTracer.cs" Link="Common\GeneralTracer.cs" />
7475
<Compile Include="..\GeneralUpdate.Common\Shared\Object\Configinfo.cs" Link="Common\Configinfo.cs" />
7576
<Compile Include="..\GeneralUpdate.Common\Shared\Object\DTO\BaseResponseDTO.cs" Link="Common\BaseResponseDTO.cs" />
7677
<Compile Include="..\GeneralUpdate.Common\Shared\Object\DTO\VersionRespDTO.cs" Link="Common\VersionRespDTO.cs" />

src/c#/GeneralUpdate.Client/Program.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ static async Task Main(string[] args)
1616
{
1717
try
1818
{
19+
/*GeneralTracer.Info("Starting client");
20+
GeneralTracer.Error("test error");
21+
GeneralTracer.Debug("test debug");
22+
GeneralTracer.SetTracingEnabled(false);
23+
GeneralTracer.Dispose();*/
24+
1925
Console.WriteLine($"主程序初始化,{DateTime.Now}!");
2026
Console.WriteLine("当前运行目录:" + Thread.GetDomain().BaseDirectory);
2127
await Task.Delay(2000);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public override async Task<GeneralClientBootstrap> LaunchAsync()
5050
}
5151
catch (Exception exception)
5252
{
53-
Debug.WriteLine(exception.Message);
53+
GeneralTracer.Error("The LaunchAsync method in the GeneralClientBootstrap class throws an exception." , exception);
5454
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(exception, exception.Message));
5555
}
5656
return this;
@@ -243,7 +243,7 @@ private async Task ExecuteWorkflowAsync()
243243
}
244244
catch (Exception exception)
245245
{
246-
Debug.WriteLine(exception.Message);
246+
GeneralTracer.Error("The ExecuteWorkflowAsync method in the GeneralClientBootstrap class throws an exception." , exception);
247247
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(exception, exception.Message));
248248
}
249249
}
@@ -266,7 +266,7 @@ private async Task Download()
266266
}
267267
catch (Exception exception)
268268
{
269-
Debug.WriteLine(exception.Message);
269+
GeneralTracer.Error("The Download method in the GeneralClientBootstrap class throws an exception." , exception);
270270
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(exception, exception.Message));
271271
}
272272
}
@@ -363,13 +363,13 @@ private void CallSmallBowlHome(string processName)
363363
var processes = Process.GetProcessesByName(processName);
364364
if (processes.Length == 0)
365365
{
366-
Debug.WriteLine($"No process named {processName} found.");
366+
GeneralTracer.Info($"No process named {processName} found.");
367367
return;
368368
}
369369

370370
foreach (var process in processes)
371371
{
372-
Debug.WriteLine($"Killing process {process.ProcessName} (ID: {process.Id})");
372+
GeneralTracer.Info($"Killing process {process.ProcessName} (ID: {process.Id})");
373373
process.Kill();
374374
}
375375
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Threading;
99
using System.Threading.Tasks;
1010
using GeneralUpdate.Common.FileBasic;
11+
using GeneralUpdate.Common.Internal;
1112
using GeneralUpdate.Common.Internal.Bootstrap;
1213
using GeneralUpdate.Common.Internal.JsonContext;
1314
using GeneralUpdate.Common.Shared.Object;
@@ -53,7 +54,7 @@ await Task.Run(() =>
5354
catch (Exception ex)
5455
{
5556
var error = ex.Message + "\n" + ex.StackTrace;
56-
Trace.WriteLine(error);
57+
GeneralTracer.Error(error);
5758
throw new Exception(error);
5859
}
5960
});

src/c#/GeneralUpdate.ClientCore/GeneralUpdate.ClientCore.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
<Compile Include="..\GeneralUpdate.Common\Internal\Pipeline\PipelineContext.cs" Link="Common\PipelineContext.cs" />
6262
<Compile Include="..\GeneralUpdate.Common\Internal\Strategy\AbstractStrategy.cs" Link="Common\AbstractStrategy.cs" />
6363
<Compile Include="..\GeneralUpdate.Common\Internal\Strategy\IStrategy.cs" Link="Common\IStrategy.cs" />
64+
<Compile Include="..\GeneralUpdate.Common\Internal\Trace\GeneralTracer.cs" Link="Common\GeneralTracer.cs" />
6465
<Compile Include="..\GeneralUpdate.Common\Shared\Object\Configinfo.cs" Link="Common\Configinfo.cs" />
6566
<Compile Include="..\GeneralUpdate.Common\Shared\Object\DTO\BaseResponseDTO.cs" Link="Common\BaseResponseDTO.cs" />
6667
<Compile Include="..\GeneralUpdate.Common\Shared\Object\DTO\VersionRespDTO.cs" Link="Common\VersionRespDTO.cs" />

src/c#/GeneralUpdate.ClientCore/Hubs/UpgradeHubService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
2-
using System.Diagnostics;
32
using System.Threading.Tasks;
3+
using GeneralUpdate.Common.Internal;
44
using GeneralUpdate.Common.Internal.JsonContext;
55
using Microsoft.AspNetCore.SignalR;
66
using Microsoft.AspNetCore.SignalR.Client;
@@ -61,7 +61,7 @@ public async Task StartAsync()
6161
}
6262
catch (Exception e)
6363
{
64-
Debug.WriteLine(e);
64+
GeneralTracer.Error("The StartAsync method in the UpgradeHubService class throws an exception." , e);
6565
}
6666
}
6767

@@ -73,7 +73,7 @@ public async Task StopAsync()
7373
}
7474
catch (Exception e)
7575
{
76-
Debug.WriteLine(e);
76+
GeneralTracer.Error("The StopAsync method in the UpgradeHubService class throws an exception." , e);
7777
}
7878
}
7979

@@ -85,7 +85,7 @@ public async Task DisposeAsync()
8585
}
8686
catch (Exception e)
8787
{
88-
Debug.WriteLine(e);
88+
GeneralTracer.Error("The DisposeAsync method in the UpgradeHubService class throws an exception." , e);
8989
}
9090
}
9191
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ await VersionService.Report(_configinfo.ReportUrl
8585
}
8686
catch (Exception e)
8787
{
88-
Debug.WriteLine(e);
88+
GeneralTracer.Error("The ExecuteAsync method in the LinuxStrategy class throws an exception." , e);
8989
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message));
9090
}
9191
}
@@ -109,7 +109,7 @@ public override void StartApp()
109109
}
110110
catch (Exception e)
111111
{
112-
Debug.WriteLine(e);
112+
GeneralTracer.Error("The StartApp method in the LinuxStrategy class throws an exception." , e);
113113
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message));
114114
}
115115
finally

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ await VersionService.Report(_configinfo.ReportUrl
8181
}
8282
catch (Exception e)
8383
{
84-
Debug.WriteLine(e);
84+
GeneralTracer.Error("The ExecuteAsync method in the WindowsStrategy class throws an exception." , e);
8585
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message));
8686
}
8787
}
@@ -104,7 +104,7 @@ public override void StartApp()
104104
}
105105
catch (Exception e)
106106
{
107-
Debug.WriteLine(e);
107+
GeneralTracer.Error("The StartApp method in the WindowsStrategy class throws an exception." , e);
108108
EventManager.Instance.Dispatch(this, new ExceptionEventArgs(e, e.Message));
109109
}
110110
finally

src/c#/GeneralUpdate.Common/Compress/ZipCompressionStrategy.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Text;
88
using System.Text.RegularExpressions;
99
using GeneralUpdate.Common.FileBasic;
10+
using GeneralUpdate.Common.Internal;
1011

1112
namespace GeneralUpdate.Common.Compress;
1213

@@ -103,7 +104,7 @@ public void Compress(string sourceDirectoryName
103104
}
104105
catch (Exception exception)
105106
{
106-
Debug.WriteLine(exception);
107+
GeneralTracer.Error("The Compress method in the ZipCompressionStrategy class throws an exception." , exception);
107108
throw new Exception($"Failed to compress archive: {exception.Message}");
108109
}
109110
}
@@ -164,7 +165,7 @@ public void Decompress(string zipFilePath, string unZipDir, Encoding encoding)
164165
}
165166
catch (Exception exception)
166167
{
167-
Debug.WriteLine(exception);
168+
GeneralTracer.Error("The Decompress method in the ZipCompressionStrategy class throws an exception." , exception);
168169
throw new Exception($"Failed to decompress archive: {exception.Message}");
169170
}
170171
}

src/c#/GeneralUpdate.Common/Download/DownloadTask.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Net.Http;
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using GeneralUpdate.Common.Internal;
89
using GeneralUpdate.Common.Shared.Object;
910

1011
namespace GeneralUpdate.Common.Download
@@ -41,7 +42,7 @@ public async Task LaunchAsync()
4142
}
4243
catch (Exception exception)
4344
{
44-
Debug.WriteLine(exception.Message);
45+
GeneralTracer.Error("The LaunchAsync method in the DownloadTask class throws an exception." , exception);
4546
_manager.OnMultiDownloadError(this, new MultiDownloadErrorEventArgs(exception, _version));
4647
}
4748
}
@@ -82,7 +83,7 @@ private async Task DownloadFileRangeAsync(string url, string path)
8283
catch (Exception exception)
8384
{
8485
OnDownloadCompleted(false);
85-
Debug.WriteLine(exception.Message);
86+
GeneralTracer.Error("The DownloadFileRangeAsync method in the DownloadTask class throws an exception." , exception);
8687
_manager.OnMultiDownloadError(this, new MultiDownloadErrorEventArgs(exception, _version));
8788
}
8889
}
@@ -124,7 +125,7 @@ private async Task WriteFileAsync(string tempPath, byte[] chunk, long totalBytes
124125
catch (Exception exception)
125126
{
126127
OnDownloadCompleted(false);
127-
Debug.WriteLine(exception);
128+
GeneralTracer.Error("The WriteFileAsync method in the DownloadTask class throws an exception." , exception);
128129
_manager.OnMultiDownloadError(this, new MultiDownloadErrorEventArgs(exception, _version));
129130
}
130131
}
@@ -170,7 +171,7 @@ private void OnDownloadCompleted(bool isComplated)
170171
}
171172
catch (Exception exception)
172173
{
173-
Debug.WriteLine(exception.Message);
174+
GeneralTracer.Error(exception.Message, exception);
174175
_manager.OnMultiDownloadError(this, new MultiDownloadErrorEventArgs(exception, _version));
175176
}
176177
}
@@ -270,12 +271,12 @@ private void DisposeTimer()
270271
}
271272
catch (ObjectDisposedException exception)
272273
{
273-
Debug.WriteLine("Timer has already been disposed: " + exception.Message);
274+
GeneralTracer.Error("Timer has already been disposed: " + exception.Message);
274275
_manager.OnMultiDownloadError(this, new MultiDownloadErrorEventArgs(exception, _version));
275276
}
276277
catch (Exception exception)
277278
{
278-
Debug.WriteLine("An error occurred while disposing the timer: " + exception.Message);
279+
GeneralTracer.Error("An error occurred while disposing the timer.", exception);
279280
_manager.OnMultiDownloadError(this, new MultiDownloadErrorEventArgs(exception, _version));
280281
}
281282
finally

0 commit comments

Comments
 (0)