Skip to content

Commit 52dcc24

Browse files
author
agile.zhou
committed
syslog message refine
1 parent b4f0d04 commit 52dcc24

File tree

4 files changed

+21
-123
lines changed

4 files changed

+21
-123
lines changed

src/AgileConfig.Server.Apisite/Middleware/LocalizationMiddleware.cs

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/AgileConfig.Server.Apisite/Startup.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
using System;
22
using System.IO;
33
using System.Net;
4-
using System.Globalization;
54
using AgileConfig.Server.Apisite.UIExtension;
65
using AgileConfig.Server.Apisite.Websocket;
7-
using AgileConfig.Server.Apisite.Middleware;
86
using AgileConfig.Server.Common;
97
using AgileConfig.Server.Common.RestClient;
108
using AgileConfig.Server.Data.Freesql;
@@ -68,9 +66,6 @@ public void ConfigureServices(IServiceCollection services)
6866

6967
services.AddMemoryCache();
7068

71-
// Add localization services
72-
AddLocalizationServices(services);
73-
7469
services.AddCors();
7570
services.AddMvc().AddRazorRuntimeCompilation().AddControllersAsServices();
7671

src/AgileConfig.Server.Service/RemoteServerNodeProxy.cs

Lines changed: 16 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using AgileConfig.Server.IService;
66
using Microsoft.Extensions.Logging;
77
using System;
8-
using System.Collections.Concurrent;
98
using System.Collections.Generic;
109
using System.Threading.Tasks;
1110

@@ -17,13 +16,14 @@ public class RemoteServerNodeProxy : IRemoteServerNodeProxy
1716
private readonly IRestClient _restClient;
1817
private readonly IServerNodeService _serverNodeService;
1918
private readonly ISysLogService _sysLogService;
20-
21-
private static ConcurrentDictionary<string, ClientInfos> _serverNodeClientReports =
22-
new ConcurrentDictionary<string, ClientInfos>();
23-
19+
private static readonly Dictionary<string, string> _modules = new()
20+
{
21+
{ "r", "Registration Center" },
22+
{ "c", "Configuration Center" }
23+
};
2424

2525
public RemoteServerNodeProxy(
26-
ILoggerFactory loggerFactory,
26+
ILoggerFactory loggerFactory,
2727
IRestClient restClient,
2828
IServerNodeService serverNodeService,
2929
ISysLogService sysLogService)
@@ -47,20 +47,12 @@ public async Task<bool> AllClientsDoActionAsync(string address, WebsocketAction
4747
return false;
4848
}, 5);
4949

50-
var module = "";
51-
if (action.Module == "r")
52-
{
53-
module = "注册中心";
54-
}
55-
if (action.Module == "c")
56-
{
57-
module = "配置中心";
58-
}
50+
_modules.TryGetValue(action.Module, out var moduleName);
5951
await _sysLogService.AddSysLogAsync(new SysLog
6052
{
6153
LogTime = DateTime.Now,
6254
LogType = result ? SysLogType.Normal : SysLogType.Warn,
63-
LogText = $"通知节点【{address}】所有客户端:【{module}】【{action.Action}】 响应:{(result ? "成功" : "失败")}"
55+
LogText = $"Notified node [{address}] all clients: [{moduleName}] [{action.Action}] Response: {(result ? "Success" : "Failed")}"
6456
});
6557

6658
return result;
@@ -80,21 +72,13 @@ public async Task<bool> AppClientsDoActionAsync(string address, string appId, st
8072
return false;
8173
}, 5);
8274

83-
var module = "";
84-
if (action.Module == "r")
85-
{
86-
module = "注册中心";
87-
}
88-
if (action.Module == "c")
89-
{
90-
module = "配置中心";
91-
}
75+
_modules.TryGetValue(action.Module, out var moduleName);
9276
await _sysLogService.AddSysLogAsync(new SysLog
9377
{
9478
LogTime = DateTime.Now,
9579
LogType = result ? SysLogType.Normal : SysLogType.Warn,
9680
AppId = appId,
97-
LogText = $"通知节点【{address}】应用【{appId}】的客户端:【{module}】【{action.Action}】 响应:{(result ? "成功" : "失败")}"
81+
LogText = $"Notified node [{address}] app [{appId}] clients: [{moduleName}] [{action.Action}] Response: {(result ? "Success" : "Failed")}"
9882
});
9983
return result;
10084
}
@@ -106,41 +90,15 @@ public async Task<bool> OneClientDoActionAsync(string address, string clientId,
10690
var url = $"{address}/RemoteOP/OneClientDoAction?clientId={clientId}";
10791
dynamic result = await _restClient.PostAsync<dynamic>(url, action);
10892

109-
if ((bool)result.success)
110-
{
111-
if (action.Action == ActionConst.Offline)
112-
{
113-
if (_serverNodeClientReports.ContainsKey(address))
114-
{
115-
if (_serverNodeClientReports[address].Infos != null)
116-
{
117-
var report = _serverNodeClientReports[address];
118-
report.Infos.RemoveAll(c => c.Id == clientId);
119-
report.ClientCount = report.Infos.Count;
120-
}
121-
}
122-
}
123-
124-
return true;
125-
}
126-
127-
return false;
93+
return (bool)result.success;
12894
}, 5);
12995

130-
var module = "";
131-
if (action.Module == "r")
132-
{
133-
module = "注册中心";
134-
}
135-
if (action.Module == "c")
136-
{
137-
module = "配置中心";
138-
}
96+
_modules.TryGetValue(action.Module, out var moduleName);
13997
await _sysLogService.AddSysLogAsync(new SysLog
14098
{
14199
LogTime = DateTime.Now,
142100
LogType = result ? SysLogType.Normal : SysLogType.Warn,
143-
LogText = $"通知节点【{address}】的客户端【{clientId}】:【{module}】【{action.Action}】 响应:{(result ? "成功" : "失败")}"
101+
LogText = $"Notified node [{address}] client [{clientId}]: [{moduleName}] [{action.Action}] Response: {(result ? "Success" : "Failed")}"
144102
});
145103

146104
return result;
@@ -210,7 +168,7 @@ public async Task TestEchoAsync(string address)
210168
node.Status = NodeStatus.Offline;
211169
_logger.LogInformation(e, "Try test node {0} echo , but fail .", node.Id);
212170
}
213-
171+
214172
if (node.Status == NodeStatus.Offline)
215173
{
216174
DateTime? time = node.LastEchoTime;
@@ -225,7 +183,7 @@ public async Task TestEchoAsync(string address)
225183
return;
226184
}
227185
}
228-
186+
229187
await _serverNodeService.UpdateAsync(node);
230188
}
231189

@@ -259,7 +217,7 @@ public async Task ClearConfigServiceCache(string address)
259217
_logger.LogError(e, "Try to clear node {0}'s config cache , but fail .", address);
260218
}
261219
}
262-
220+
263221
public async Task ClearServiceInfoCache(string address)
264222
{
265223
try

test/AgileConfig.Server.CommonTests/AgileConfig.Server.CommonTests.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
@@ -7,10 +7,10 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
11-
<PackageReference Include="MSTest.TestAdapter" Version="3.2.0" />
12-
<PackageReference Include="MSTest.TestFramework" Version="3.2.0" />
13-
<PackageReference Include="coverlet.collector" Version="6.0.0">
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
11+
<PackageReference Include="MSTest.TestAdapter" Version="4.0.0-preview.25372.6" />
12+
<PackageReference Include="MSTest.TestFramework" Version="4.0.0-preview.25372.6" />
13+
<PackageReference Include="coverlet.collector" Version="6.0.4">
1414
<PrivateAssets>all</PrivateAssets>
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1616
</PackageReference>

0 commit comments

Comments
 (0)