From bf2aa9dd56432a74940ca1bb08fb4d7eaee37045 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期五, 27 三月 2026 11:03:37 +0800
Subject: [PATCH] feat(WCS): 完善 WIDESEAWCS_Tasks 模块日志系统
---
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotStateManager.cs | 23 +++++++++++++++++++++--
1 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotStateManager.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotStateManager.cs
index 3bafe10..89f0910 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotStateManager.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotStateManager.cs
@@ -1,6 +1,8 @@
+using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using WIDESEAWCS_Common;
using WIDESEAWCS_Core.Caches;
+using WIDESEAWCS_Core.LogHelper;
using WIDESEAWCS_QuartzJob;
namespace WIDESEAWCS_Tasks
@@ -20,12 +22,19 @@
private readonly ICacheService _cache;
/// <summary>
+ /// 鏃ュ織璁板綍鍣�
+ /// </summary>
+ private readonly ILogger _logger;
+
+ /// <summary>
/// 鏋勯�犲嚱鏁�
/// </summary>
/// <param name="cache">缂撳瓨鏈嶅姟瀹炰緥锛堥�氬父涓� HybridCacheService锛�</param>
- public RobotStateManager(ICacheService cache)
+ /// <param name="logger">鏃ュ織璁板綍鍣�</param>
+ public RobotStateManager(ICacheService cache, ILogger logger)
{
_cache = cache;
+ _logger = logger;
}
/// <summary>
@@ -100,6 +109,8 @@
newState.Version = DateTime.UtcNow.Ticks;
// 鐩存帴娣诲姞鍒扮紦瀛�
_cache.AddObject(cacheKey, newState);
+ _logger.LogDebug("TryUpdateStateSafely锛氬垱寤烘柊鐘舵�侊紝IP: {IpAddress}", ipAddress);
+ QuartzLogger.Debug($"鍒涘缓鏂扮姸鎬侊紝IP: {ipAddress}", ipAddress);
return true;
}
@@ -110,12 +121,20 @@
newState.Version = DateTime.UtcNow.Ticks;
// 灏濊瘯瀹夊叏鏇存柊锛屽鏋滅増鏈啿绐佸垯杩斿洖 false
- return _cache.TrySafeUpdate(
+ bool success = _cache.TrySafeUpdate(
cacheKey,
newState,
expectedVersion,
s => s.Version
);
+
+ if (!success)
+ {
+ _logger.LogWarning("TryUpdateStateSafely锛氱増鏈啿绐侊紝鏇存柊澶辫触锛孖P: {IpAddress}锛屾湡鏈涚増鏈�: {ExpectedVersion}", ipAddress, expectedVersion);
+ QuartzLogger.Warn($"鐗堟湰鍐茬獊锛屾洿鏂板け璐ワ紝IP: {ipAddress}", ipAddress);
+ }
+
+ return success;
}
/// <summary>
--
Gitblit v1.9.3