规范并补充日志内容
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Ayay.SerilogLogs;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Serilog;
|
||||
using SHH.CameraSdk;
|
||||
using SHH.Contracts;
|
||||
|
||||
@@ -9,6 +11,8 @@ namespace SHH.CameraService
|
||||
/// </summary>
|
||||
public class RemoveCameraHandler : ICommandHandler
|
||||
{
|
||||
private static ILogger _sysLog = Log.ForContext("SourceContext", LogModules.Core);
|
||||
|
||||
private readonly CameraManager _cameraManager;
|
||||
|
||||
/// <summary>
|
||||
@@ -50,7 +54,7 @@ namespace SHH.CameraService
|
||||
|
||||
if (deviceId <= 0)
|
||||
{
|
||||
Console.WriteLine($"[{ActionName}] 收到无效指令: ID解析失败 ({payload})");
|
||||
_sysLog.Warning($"[Sync] 收到无效指令, ID解析失败 ({payload})");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -58,26 +62,25 @@ namespace SHH.CameraService
|
||||
var device = _cameraManager.GetDevice(deviceId);
|
||||
if (device == null)
|
||||
{
|
||||
Console.WriteLine($"[{ActionName}] 设备 {deviceId} 已经不在管理池中,无需操作。");
|
||||
_sysLog.Warning($"[Sync] 设备 {deviceId} 已经不在管理池中,无需操作.");
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. 安全移除
|
||||
// 这里建议增加审计日志,记录谁触发了删除(如果协议里有用户信息的话)
|
||||
device.AddAuditLog("收到远程指令:彻底移除设备");
|
||||
Console.WriteLine($"[{ActionName}] 正在安全移除设备: {deviceId} ({device.Config.Name})");
|
||||
_sysLog.Debug($"[Sync] 收到远程指令, 正在安全移除设备, ID:{deviceId} Name:{device.Config.Name} .");
|
||||
|
||||
// CameraManager 内部会:StopAsync -> DisposeAsync -> TryRemove -> SaveChanges
|
||||
await _cameraManager.RemoveDeviceAsync(deviceId);
|
||||
|
||||
Console.WriteLine($"[{ActionName}] 设备 {deviceId} 已彻底清理并从持久化库中移除。");
|
||||
_sysLog.Information($"[Sync] 收到远程指令, 设备, ID:{deviceId} Name:{device.Config.Name}已彻底清理并从持久化库中移除 .");
|
||||
|
||||
// 4. (可选) 此处可以调用 CommandDispatcher 发送 Success ACK
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 捕获异常,防止影响全局 Socket 轮询
|
||||
Console.WriteLine($"[{ActionName}] 移除设备 {deviceId} 过程中发生致命错误: {ex.Message}");
|
||||
_sysLog.Error($"[Sync] 移除设备, ID:{deviceId} 过程中发生致命错误, {ex.Message}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user