Skip to content

Commit 42ea6ad

Browse files
committed
refactor(logging): 统一使用LogHelper替代LogHelper.Console方法
将所有使用LogHelper.Console的日志输出替换为LogHelper的对应级别方法,保持日志输出方式的一致性
1 parent 90a413f commit 42ea6ad

File tree

8 files changed

+42
-46
lines changed

8 files changed

+42
-46
lines changed

GameFrameX.StartUp/AppEnter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ internal static async Task Entry(IAppStartUp appStartUp)
9999
error = $"failed to start the server:{e}";
100100
}
101101

102-
LogHelper.ErrorConsole(error);
102+
LogHelper.Error(error);
103103
}
104104
}
105105

@@ -118,11 +118,11 @@ private static void HandleExit(string message)
118118
}
119119

120120
_exitCalled = true;
121-
LogHelper.InfoConsole("listen to the exit message from the program");
121+
LogHelper.Info("listen to the exit message from the program");
122122
GlobalSettings.IsAppRunning = false;
123123
_appStartUp.StopAsync(message).Wait();
124124
AppExitHandler.Kill();
125-
LogHelper.InfoConsole("exit procedure");
125+
LogHelper.Info("exit procedure");
126126
_gameLoopTask?.Wait();
127127
LogHelper.FlushAndSave();
128128
}

GameFrameX.StartUp/AppStartUpBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public bool Init(string serverType, AppSetting setting, string[] args = null)
131131
public virtual async Task StopAsync(string message = "")
132132
{
133133
GlobalSettings.IsAppRunning = false;
134-
LogHelper.ErrorConsole($"服务器类型:{Setting.ServerType} 停止! 终止原因:{message} 配置信息: {Setting.ToFormatString()}");
134+
LogHelper.Error($"服务器类型:{Setting.ServerType} 停止! 终止原因:{message} 配置信息: {Setting.ToFormatString()}");
135135
await StopServerAsync();
136136
AppExitSource?.TrySetResult(message);
137137
LogHelper.FlushAndSave();

GameFrameX.StartUp/AppStartUpByHTTPServer.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private async Task StartHttpServer(List<BaseHttpHandler> baseHandler, Func<strin
7474
// 检查是否启用HTTP服务
7575
if (!Setting.IsEnableHttp)
7676
{
77-
LogHelper.InfoConsole("The HTTP service is disabled, and the startup is ignored");
77+
LogHelper.Info($"The HTTP service is disabled, and the startup is ignored");
7878
return;
7979
}
8080

@@ -89,10 +89,10 @@ private async Task StartHttpServer(List<BaseHttpHandler> baseHandler, Func<strin
8989
throw new ArgumentException("The HTTP address must end in /", nameof(Setting.HttpUrl));
9090
}
9191

92-
LogHelper.InfoConsole("start the [HTTP] server...");
92+
LogHelper.Info($"start the [HTTP] server...");
9393
if (!Setting.HttpPort.IsRange(5000, ushort.MaxValue - 1))
9494
{
95-
LogHelper.WarningConsole($"start the [HTTP] server port [{Setting.HttpPort}] out of range [5000-{ushort.MaxValue - 1}],The HTTP service cannot be started, and the startup is ignored");
95+
LogHelper.Warning($"start the [HTTP] server port [{Setting.HttpPort}] out of range [5000-{ushort.MaxValue - 1}],The HTTP service cannot be started, and the startup is ignored");
9696
return;
9797
}
9898

@@ -161,7 +161,7 @@ private async Task StartHttpServer(List<BaseHttpHandler> baseHandler, Func<strin
161161

162162
foreach (var ip in ipList)
163163
{
164-
LogHelper.DebugConsole($"Swagger UI can be passed http://{ip}:{Setting.HttpPort}/swagger access");
164+
LogHelper.Debug($"Swagger UI can be passed http://{ip}:{Setting.HttpPort}/swagger access");
165165
}
166166
}
167167

@@ -177,15 +177,15 @@ private async Task StartHttpServer(List<BaseHttpHandler> baseHandler, Func<strin
177177
app.MapPrometheusScrapingEndpoint();
178178
foreach (var ip in ipList)
179179
{
180-
LogHelper.InfoConsole($"Prometheus metrics the endpoint is enabled: http://{ip}:{Setting.HttpPort}/metrics");
180+
LogHelper.Info($"Prometheus metrics the endpoint is enabled: http://{ip}:{Setting.HttpPort}/metrics");
181181
}
182182
}
183183
else if (Setting.IsOpenTelemetry && Setting.IsOpenTelemetryMetrics && Setting.MetricsPort > 0)
184184
{
185-
LogHelper.InfoConsole($"Prometheus metrics The service will be provided on the standalone port {Setting.MetricsPort}");
185+
LogHelper.Info($"Prometheus metrics The service will be provided on the standalone port {Setting.MetricsPort}");
186186
foreach (var ip in ipList)
187187
{
188-
LogHelper.InfoConsole($"Prometheus metrics the endpoint is enabled: http://{ip}:{Setting.MetricsPort}/metrics");
188+
LogHelper.Info($"Prometheus metrics the endpoint is enabled: http://{ip}:{Setting.MetricsPort}/metrics");
189189
}
190190
}
191191

@@ -217,7 +217,7 @@ private async Task StartHttpServer(List<BaseHttpHandler> baseHandler, Func<strin
217217
}
218218

219219
await app.StartAsync();
220-
LogHelper.InfoConsole($"Start [HTTP] Server Startup Complete - Port: {Setting.HttpPort}");
220+
LogHelper.Info($"Start [HTTP] Server Startup Complete - Port: {Setting.HttpPort}");
221221
}
222222
else
223223
{

GameFrameX.StartUp/AppStartUpByServer.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ private async Task StartServer(List<BaseHttpHandler> baseHandler, Func<string, B
259259
// 检查TCP端口是否可用
260260
if (Setting.InnerPort > 0 && NetHelper.PortIsAvailable(Setting.InnerPort))
261261
{
262-
LogHelper.InfoConsole($"start tcp server type: {ServerType}, address: {Setting.InnerHost}, port: {Setting.InnerPort}");
262+
LogHelper.Info($"start tcp server type: {ServerType}, address: {Setting.InnerHost}, port: {Setting.InnerPort}");
263263
multipleServerHostBuilder.AddServer<IMessage, MessageObjectPipelineFilter>(builder =>
264264
{
265265
var serverBuilder = builder
@@ -290,29 +290,29 @@ private async Task StartServer(List<BaseHttpHandler> baseHandler, Func<string, B
290290
// if (serviceDescriptor.ServiceType == typeof(IPackageDecoder<IMessage>))
291291
// {
292292
// serviceDescriptor.ImplementationInstance ;
293-
// LogHelper.Console("XX");
293+
// LogHelper.Info($"XX");
294294
// }
295295
// }
296296
});
297297
});
298-
LogHelper.InfoConsole($"start tcp server startup complete type: {ServerType}, address: {Setting.InnerHost}, port: {Setting.InnerPort}");
298+
LogHelper.Info($"start tcp server startup complete type: {ServerType}, address: {Setting.InnerHost}, port: {Setting.InnerPort}");
299299
}
300300
else
301301
{
302-
LogHelper.WarningConsole($"start tcp server start failed type: {ServerType}, address: {Setting.InnerHost}, port: {Setting.InnerPort}, cause: the port is invalid or occupied");
302+
LogHelper.Warning($"start tcp server start failed type: {ServerType}, address: {Setting.InnerHost}, port: {Setting.InnerPort}, cause: the port is invalid or occupied");
303303
}
304304
}
305305
else
306306
{
307-
LogHelper.InfoConsole($"start tcp server type: {ServerType}, address: {Setting.InnerHost}, port: {Setting.InnerPort}, cause: the tcp server is disabled");
307+
LogHelper.Info($"start tcp server type: {ServerType}, address: {Setting.InnerHost}, port: {Setting.InnerPort}, cause: the tcp server is disabled");
308308
}
309309

310310
// 检查WebSocket端口是否可用
311311
if (Setting.IsEnableWebSocket)
312312
{
313313
if (Setting.WsPort is > 0 and < ushort.MaxValue && NetHelper.PortIsAvailable(Setting.WsPort))
314314
{
315-
LogHelper.InfoConsole("start the websocket server...");
315+
LogHelper.Info($"start the websocket server type: {ServerType}, port: {Setting.WsPort}");
316316

317317
// 配置并启动WebSocket服务器
318318
multipleServerHostBuilder.AddWebSocketServer(builder =>
@@ -333,16 +333,16 @@ private async Task StartServer(List<BaseHttpHandler> baseHandler, Func<string, B
333333
});
334334
});
335335
});
336-
LogHelper.InfoConsole($"start websocket server startup complete type: {ServerType}, port: {Setting.WsPort}");
336+
LogHelper.Info($"start websocket server startup complete type: {ServerType}, port: {Setting.WsPort}");
337337
}
338338
else
339339
{
340-
LogHelper.WarningConsole($"start websocket server start failed type: {ServerType}, port: {Setting.WsPort}, cause: the port is invalid or occupied");
340+
LogHelper.Warning($"start websocket server start failed type: {ServerType}, port: {Setting.WsPort}, cause: the port is invalid or occupied");
341341
}
342342
}
343343
else
344344
{
345-
LogHelper.InfoConsole($"start websocket server start failed type: {ServerType}, port: {Setting.WsPort}, cause: WebSocket service is not enabled");
345+
LogHelper.Info($"start websocket server start failed type: {ServerType}, port: {Setting.WsPort}, cause: WebSocket service is not enabled");
346346
}
347347

348348
// await StartHttpServerAsync(hostBuilder,baseHandler, httpFactory, aopHandlerTypes, minimumLevelLogLevel);
@@ -352,7 +352,7 @@ private async Task StartServer(List<BaseHttpHandler> baseHandler, Func<string, B
352352
var metricsServer = await OpenTelemetryExtensions.CreateMetricsServerAsync(Setting, "TCP");
353353
if (metricsServer is not null)
354354
{
355-
LogHelper.InfoConsole($"The standalone metric server is started on the port: {Setting.MetricsPort}");
355+
LogHelper.Info($"The standalone metric server is started on the port: {Setting.MetricsPort}");
356356
}
357357

358358
// 配置监控和跟踪

GameFrameX.StartUp/Extensions/HealthChecksExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,14 @@ public static IApplicationBuilder UseGameFrameXHealthChecks(this IApplicationBui
194194
app.UseHealthChecks(OpenTelemetryHealthCheckPath, openTelemetryHealthCheckOptions);
195195
}
196196

197-
LogHelper.InfoConsole("the health check endpoint is enabled:");
197+
LogHelper.Info("the health check endpoint is enabled:");
198198
foreach (var ip in ipList)
199199
{
200-
LogHelper.InfoConsole($"- detailed health checks: http://{ip}:{setting.HttpPort}{DefaultHealthCheckPath}");
201-
LogHelper.InfoConsole($"- simple health check: http://{ip}:{setting.HttpPort}{SimpleHealthCheckPath}");
200+
LogHelper.Info($"- detailed health checks: http://{ip}:{setting.HttpPort}{DefaultHealthCheckPath}");
201+
LogHelper.Info($"- simple health check: http://{ip}:{setting.HttpPort}{SimpleHealthCheckPath}");
202202
if (setting.IsOpenTelemetry)
203203
{
204-
LogHelper.InfoConsole($"- OpenTelemetry check: http://{ip}:{setting.HttpPort}{OpenTelemetryHealthCheckPath}");
204+
LogHelper.Info($"- OpenTelemetry check: http://{ip}:{setting.HttpPort}{OpenTelemetryHealthCheckPath}");
205205
}
206206
}
207207

GameFrameX.StartUp/Extensions/OpenTelemetryExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ public static async Task<WebApplication> CreateMetricsServerAsync(AppSetting set
274274
var ipList = NetHelper.GetLocalIpList();
275275
foreach (var ip in ipList)
276276
{
277-
LogHelper.InfoConsole($"独立 Prometheus metrics 端点已启用: http://{ip}:{setting.MetricsPort}/metrics");
278-
LogHelper.InfoConsole($"独立 Metrics 健康检查端点: http://{ip}:{setting.MetricsPort}/health");
277+
LogHelper.Info($"独立 Prometheus metrics 端点已启用: http://{ip}:{setting.MetricsPort}/metrics");
278+
LogHelper.Info($"独立 Metrics 健康检查端点: http://{ip}:{setting.MetricsPort}/health");
279279
}
280280

281281
return app;

GameFrameX.StartUp/GameApp.cs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static class GameApp
7272
/// 键为类型,值为对应的启动标签属性。
7373
/// </remarks>
7474
private static readonly Dictionary<Type, StartUpTagAttribute> StartUpTypes = new();
75-
75+
7676
/// <summary>
7777
/// List of startup tasks for concurrent execution / 用于并发执行的启动任务列表
7878
/// </summary>
@@ -124,13 +124,13 @@ public static async Task Entry(string[] args, Action initAction, Action<LogOptio
124124
}
125125
catch (Exception e)
126126
{
127-
LogHelper.ErrorConsole(e.Message);
127+
LogHelper.Error(e.Message);
128128
}
129129

130130
var serverType = launcherOptions?.ServerType;
131131
if (!serverType.IsNullOrEmpty())
132132
{
133-
LogHelper.Console("the type of server that is launched : " + serverType);
133+
LogHelper.Info($"the type of server that is launched : {serverType}");
134134
}
135135

136136
LogOptions.Default.LogType = serverType;
@@ -156,7 +156,7 @@ public static async Task Entry(string[] args, Action initAction, Action<LogOptio
156156

157157
if (!LogOptions.Default.GrafanaLokiLabels.TryAdd(property.Name, value))
158158
{
159-
LogHelper.WarningConsole($"Grafana Loki label {property.Name} already exists, will be ignored");
159+
LogHelper.Warning($"Grafana Loki label {property.Name} already exists, will be ignored");
160160
}
161161
}
162162

@@ -239,11 +239,11 @@ public static async Task Entry(string[] args, Action initAction, Action<LogOptio
239239
var appSetting = appSettings.FirstOrDefault(m => m.ServerType == serverType);
240240
if (appSetting != null)
241241
{
242-
LogHelper.InfoConsole($"Finding the boot configuration for the corresponding server type in the configuration file will be configured to boot=>{startKv.Value.ServerType}");
242+
LogHelper.Info($"Finding the boot configuration for the corresponding server type in the configuration file will be configured to boot=>{startKv.Value.ServerType}");
243243
}
244244
else
245245
{
246-
LogHelper.WarningConsole($"If no startup configuration is found for the server type, it will start with the default configuration=>{startKv.Value.ServerType}");
246+
LogHelper.Warning($"If no startup configuration is found for the server type, it will start with the default configuration=>{startKv.Value.ServerType}");
247247
appSetting = launcherOptions.Adapt<AppSetting>();
248248
}
249249

@@ -268,14 +268,14 @@ public static async Task Entry(string[] args, Action initAction, Action<LogOptio
268268

269269
if (isFind == false)
270270
{
271-
LogHelper.WarningConsole($"If no startup configuration is found for the server type, it will start with the default configuration=>{keyValuePair.Value.ServerType}");
271+
LogHelper.Warning($"If no startup configuration is found for the server type, it will start with the default configuration=>{keyValuePair.Value.ServerType}");
272272
Launcher(args, keyValuePair);
273273
break;
274274
}
275275
}
276276
}
277277

278-
LogHelper.InfoConsole("----------------------------The Startup Server Is Over------------------------------");
278+
LogHelper.Info($"----------------------------The Startup Server Is Over------------------------------");
279279
// ApplicationPerformanceMonitorStart(serverType);
280280
ConsoleHelper.ConsoleLogo();
281281

@@ -334,12 +334,8 @@ private static Task Start(string[] args, Type appStartUpType, string serverType,
334334
var isSuccess = startUp.Init(serverType, setting, args);
335335
if (isSuccess)
336336
{
337-
LogHelper.InfoConsole($"----------------------------START-----{serverType}------------------------------");
338-
LogHelper.InfoConsole($"----------------------------Configuration Information---------------------------");
339-
LogHelper.InfoConsole($"{startUp.Setting.ToFormatString()}");
340-
LogHelper.InfoConsole("--------------------------------------------------------------------------------");
337+
LogHelper.ShowOption($"{serverType} - Configuration Information", startUp.Setting.ToFormatString());
341338
var task = AppEnter.Entry(startUp);
342-
LogHelper.InfoConsole($"-----------------------------END------{serverType}------------------------------");
343339
return task;
344340
}
345341

GameFrameX.Utility/Setting/GlobalSettings.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,32 +113,32 @@ public static void SetCurrentSetting(AppSetting setting)
113113
{
114114
if (CurrentSetting.IsNotNull())
115115
{
116-
LogHelper.WarningConsole("The current setting already exists, cannot be set again, and this setting has been ignored.");
116+
LogHelper.Warning("The current setting already exists, cannot be set again, and this setting has been ignored.");
117117
return;
118118
}
119119

120120
ArgumentNullException.ThrowIfNull(setting, nameof(setting));
121121
if (setting.SaveDataInterval < 5000)
122122
{
123-
LogHelper.WarningConsole($"SaveDataInterval小于5000毫秒,使用默认值为:{GlobalConst.SaveIntervalInMilliSeconds} 毫秒");
123+
LogHelper.Warning($"SaveDataInterval小于5000毫秒,使用默认值为:{GlobalConst.SaveIntervalInMilliSeconds} 毫秒");
124124
setting.SaveDataInterval = GlobalConst.SaveIntervalInMilliSeconds;
125125
}
126126

127127
if (setting.HttpUrl.IsNullOrEmptyOrWhiteSpace())
128128
{
129-
LogHelper.WarningConsole("HttpUrl is empty and uses the default value of : /game/api/");
129+
LogHelper.Warning($"HttpUrl is empty and uses the default value of : /game/api/");
130130
setting.HttpUrl = "/game/api/";
131131
}
132132

133133
if (setting.NetWorkSendTimeOutSeconds < 1)
134134
{
135-
LogHelper.WarningConsole("NetWorkSendTimeOutSeconds is less than 1 second, and the default value is 5 seconds");
135+
LogHelper.Warning($"NetWorkSendTimeOutSeconds is less than 1 second, and the default value is 5 seconds");
136136
setting.NetWorkSendTimeOutSeconds = 5;
137137
}
138138

139139
if (setting.ActorRecycleTime < 1)
140140
{
141-
LogHelper.WarningConsole("ActorRecycleTime is less than 1 minute, and the default value is 5 minutes");
141+
LogHelper.Warning($"ActorRecycleTime is less than 1 minute, and the default value is 5 minutes");
142142
setting.ActorRecycleTime = 5;
143143
}
144144

0 commit comments

Comments
 (0)