Skip to content

Commit 9a2ba2f

Browse files
committed
fix: 调整日志初始化顺序以避免潜在的空引用异常
将日志类型设置和日志处理器创建的代码移动到启动初始化之前,确保在调用startUp.Init时日志系统已正确配置,防止可能的空引用问题
1 parent 43f2df1 commit 9a2ba2f

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

GameFrameX.StartUp/GameApp.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public static async Task Entry(string[] args, Action initAction, Action<LogOptio
124124
{
125125
LogHelper.Info($"the type of server that is launched : {serverType}");
126126
}
127-
127+
128128
LogOptions.Default.GrafanaLokiLabels = new Dictionary<string, string>();
129129

130130
if (launcherOptions != null)
@@ -174,7 +174,7 @@ public static async Task Entry(string[] args, Action initAction, Action<LogOptio
174174
{
175175
logTypeParts.Add(launcherOptions.ServerInstanceId.ToString());
176176
}
177-
177+
178178
if (launcherOptions.TagName.IsNotNullOrWhiteSpace())
179179
{
180180
LogOptions.Default.LogTagName = launcherOptions.TagName;
@@ -191,13 +191,11 @@ public static async Task Entry(string[] args, Action initAction, Action<LogOptio
191191
{
192192
LogOptions.Default.LogTagName = launcherOptions.Description;
193193
}
194-
194+
195195
LogOptions.Default.LogTagName = logTypeParts.Count > 0 ? string.Join("_", logTypeParts) : null;
196196
}
197197

198198
logConfiguration?.Invoke(LogOptions.Default);
199-
LogOptions.Default.LogType = serverType;
200-
LogHandler.Create(LogOptions.Default);
201199

202200
GlobalSettings.Load("Configs/app_config.json");
203201
initAction?.Invoke();
@@ -309,6 +307,8 @@ private static Task Start(string[] args, Type appStartUpType, string serverType,
309307
return Task.CompletedTask;
310308
}
311309

310+
LogOptions.Default.LogType = serverType;
311+
LogHandler.Create(LogOptions.Default);
312312
var isSuccess = startUp.Init(serverType, setting, args);
313313
if (!isSuccess)
314314
{

0 commit comments

Comments
 (0)