增加日志组件
This commit is contained in:
@@ -6,13 +6,32 @@ public class ServiceConfig
|
||||
// 1. 基础属性
|
||||
// ==========================================
|
||||
public int ParentPid { get; private set; }
|
||||
|
||||
public string AppId { get; private set; } = "Unknown_01";
|
||||
|
||||
public int NumericId { get; private set; } = 1;
|
||||
|
||||
public int BasePort { get; private set; } = 5000;
|
||||
|
||||
public int MaxPortRange { get; private set; } = 100;
|
||||
|
||||
public NetworkMode Mode { get; private set; } = NetworkMode.Passive;
|
||||
|
||||
public bool ShouldConnect => Mode == NetworkMode.Active || Mode == NetworkMode.Hybrid;
|
||||
|
||||
public string SeqServerUrl { get; private set; } = string.Empty;
|
||||
|
||||
public string SeqApiKey { get; private set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 更新实际端口
|
||||
/// </summary>
|
||||
/// <param name="port"></param>
|
||||
public void UpdateActualPort(int port)
|
||||
{
|
||||
this.BasePort = port;
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// 2. 目标地址列表 (类型变了!)
|
||||
// ==========================================
|
||||
@@ -31,12 +50,16 @@ public class ServiceConfig
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
{
|
||||
var key = args[i].ToLower().Trim();
|
||||
|
||||
// 确保不越界且下一个参数不是 key (防止 value 为空的情况)
|
||||
var value = (i + 1 < args.Length && !args[i + 1].StartsWith("--")) ? args[i + 1] : string.Empty;
|
||||
bool consumed = !string.IsNullOrEmpty(value);
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case "--pid": if (int.TryParse(value, out int pid)) config.ParentPid = pid; break;
|
||||
case "--pid":
|
||||
if (int.TryParse(value, out int pid)) config.ParentPid = pid;
|
||||
break;
|
||||
case "--appid":
|
||||
if (!string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
@@ -49,12 +72,14 @@ public class ServiceConfig
|
||||
break;
|
||||
case "--mode": if (int.TryParse(value, out int m)) config.Mode = (NetworkMode)m; break;
|
||||
case "--ports":
|
||||
if (!string.IsNullOrWhiteSpace(value) && value.Contains(","))
|
||||
{
|
||||
var parts = value.Split(',');
|
||||
if (parts.Length >= 1 && int.TryParse(parts[0], out int p)) config.BasePort = p;
|
||||
if (parts.Length >= 2 && int.TryParse(parts[1], out int r)) config.MaxPortRange = r;
|
||||
}
|
||||
ParsePortConfig(config, value);
|
||||
break;
|
||||
case "--sequris":
|
||||
config.SeqServerUrl = ParseSeqUri(value);
|
||||
break;
|
||||
case "--seqkey":
|
||||
// 去掉可能存在的分号
|
||||
config.SeqApiKey = value.Replace(";", "").Trim();
|
||||
break;
|
||||
}
|
||||
if (consumed) i++;
|
||||
@@ -62,6 +87,54 @@ public class ServiceConfig
|
||||
return config;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析端口配置
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="value"></param>
|
||||
private static void ParsePortConfig(ServiceConfig config, string value)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(value) && value.Contains(","))
|
||||
{
|
||||
var parts = value.Split(',');
|
||||
if (parts.Length >= 1 && int.TryParse(parts[0], out int p)) config.BasePort = p;
|
||||
if (parts.Length >= 2 && int.TryParse(parts[1], out int r)) config.MaxPortRange = r;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析 Seq URI
|
||||
/// </summary>
|
||||
/// <param name="rawValue"></param>
|
||||
/// <returns></returns>
|
||||
private static string ParseSeqUri(string rawValue)
|
||||
{
|
||||
// 格式: 172.16.41.241,20026,日志处置中心;
|
||||
try
|
||||
{
|
||||
rawValue = rawValue.Replace("\"", "").TrimEnd(';'); // 清理引号和末尾分号
|
||||
var parts = rawValue.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if (parts.Length >= 2)
|
||||
{
|
||||
string ip = parts[0].Trim();
|
||||
string port = parts[1].Trim();
|
||||
// 组装成标准 HTTP 格式
|
||||
return $"http://{ip}:{port}";
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从 AppId 中解析 ID
|
||||
/// </summary>
|
||||
/// <param name="appId"></param>
|
||||
/// <returns></returns>
|
||||
private static int ParseIdFromAppId(string appId)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(appId)) return 1;
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
namespace SHH.CameraSdk;
|
||||
using Ayay.SerilogLogs;
|
||||
using Serilog;
|
||||
|
||||
namespace SHH.CameraSdk;
|
||||
|
||||
/// <summary>
|
||||
/// [驱动支持层] 海康 SDK 全局资源管理器 (V3.3.1 修复版)
|
||||
@@ -103,7 +106,8 @@ public static class HikSdkManager
|
||||
// 已预热过则直接返回,避免重复执行
|
||||
if (_isWarmedUp) return;
|
||||
|
||||
Console.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] 正在进行播放库硬件探测预热,请稍候...");
|
||||
Log.ForContext("SourceContext", LogModules.Core)
|
||||
.Debug($"正在进行播放库硬件探测预热,请稍候...");
|
||||
|
||||
Stopwatch sw = Stopwatch.StartNew();
|
||||
int tempPort = -1;
|
||||
@@ -118,7 +122,8 @@ public static class HikSdkManager
|
||||
sw.Stop();
|
||||
_isWarmedUp = true;
|
||||
|
||||
Console.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] 预热完成!耗时: {sw.ElapsedMilliseconds}ms。后续调用将恢复正常。");
|
||||
Log.ForContext("SourceContext", LogModules.Core)
|
||||
.Debug($"预热完成!耗时: {sw.ElapsedMilliseconds}ms.");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Serilog" Version="4.3.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||
<PackageReference Include="OpenCvSharp4" Version="4.11.0.20250507" />
|
||||
<PackageReference Include="OpenCvSharp4.Extensions" Version="4.11.0.20250507" />
|
||||
@@ -22,6 +23,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Ayay.SerilogLogs\Ayay.SerilogLogs.csproj" />
|
||||
<ProjectReference Include="..\SHH.Contracts\SHH.Contracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user