增加日志
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
using System.Net.Sockets;
|
||||
using System.Net;
|
||||
using Ayay.SerilogLogs;
|
||||
using Ayay.SerilogLogs;
|
||||
using Grpc.Net.Client;
|
||||
using Serilog;
|
||||
using SHH.CameraSdk;
|
||||
using SHH.Contracts.Grpc;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SHH.CameraService;
|
||||
|
||||
@@ -37,8 +38,8 @@ public static class Bootstrapper
|
||||
"--uris", "localhost,9001,command,调试PC;",
|
||||
|
||||
// 日志中心配置 (格式: IP,Port,Desc)
|
||||
"--sequris", "172.16.41.241,20026,日志处置中心;",
|
||||
"--seqkey", "Shine899195994250;",
|
||||
"--sequris", "58.216.225.5,20026,日志处置中心;",
|
||||
"--seqkey", "Shine101173874928;",
|
||||
|
||||
// 端口策略
|
||||
"--mode", "1",
|
||||
@@ -48,6 +49,7 @@ public static class Bootstrapper
|
||||
|
||||
var config = ServiceConfig.BuildFromArgs(args);
|
||||
|
||||
string pcCode = config.SeqApiKey.Replace("Shine", "");
|
||||
var ops = new LogOptions
|
||||
{
|
||||
AppId = config.AppId,
|
||||
@@ -56,6 +58,7 @@ public static class Bootstrapper
|
||||
// ★这里改为从 config 读取,如果没配则留空或给个默认值
|
||||
SeqServerUrl = config.SeqServerUrl,
|
||||
SeqApiKey = config.SeqApiKey,
|
||||
PcCode = Regex.Replace(pcCode, ".{3}", "$0-").TrimEnd('-'),
|
||||
|
||||
MaxRetentionDays = 10,
|
||||
FileSizeLimitBytes = 1024L * 1024 * 1024,
|
||||
@@ -234,9 +237,10 @@ public static class Bootstrapper
|
||||
/// <summary>
|
||||
/// 向网关注册实例
|
||||
/// </summary>
|
||||
public static async Task RegisterToGatewayAsync(ServiceConfig config, ILogger logger)
|
||||
public static async Task RegisterToGatewayAsync(ServiceConfig config)
|
||||
{
|
||||
if (!config.CommandEndpoints.Any()) return;
|
||||
var gRpcLog = Log.ForContext("SourceContext", LogModules.gRpc);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -246,7 +250,7 @@ public static class Bootstrapper
|
||||
using var channel = GrpcChannel.ForAddress(targetUrl);
|
||||
var client = new GatewayProvider.GatewayProviderClient(channel);
|
||||
|
||||
logger.Information($"[Grpc] 正在执行预注册: {targetUrl}");
|
||||
gRpcLog.Information($"[gRPC] 正在执行预注册: {targetUrl}");
|
||||
var resp = await client.RegisterInstanceAsync(new RegisterRequest
|
||||
{
|
||||
InstanceId = config.AppId,
|
||||
@@ -257,11 +261,11 @@ public static class Bootstrapper
|
||||
ProcessId = Environment.ProcessId,
|
||||
Description = ""
|
||||
});
|
||||
logger.Information($"💡[Grpc] 预注册成功: {resp.Message}");
|
||||
gRpcLog.Information($"💡[gRPC] 预注册成功: {resp.Message}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error($"⚠️ [Grpc] 预注册尝试失败: {ex.Message}");
|
||||
gRpcLog.Error($"⚠️ [gRPC] 预注册尝试失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user