#0044 使用基础库层面的日志功能
This commit is contained in:
@@ -3,7 +3,7 @@ using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
using Prism.Mvvm;
|
||||
using Serilog;
|
||||
using XP.Common.Logging.Interfaces;
|
||||
using XP.Hardware.RaySource.Services;
|
||||
using XplorePlane.Models;
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace XplorePlane.Services.AppState
|
||||
{
|
||||
private readonly Dispatcher _dispatcher;
|
||||
private readonly IRaySourceService _raySourceService;
|
||||
private readonly ILogger _logger;
|
||||
private readonly ILoggerService _logger;
|
||||
private bool _disposed;
|
||||
|
||||
// ── 状态字段(通过 Interlocked.Exchange 原子替换)──
|
||||
@@ -53,17 +53,17 @@ namespace XplorePlane.Services.AppState
|
||||
|
||||
public AppStateService(
|
||||
IRaySourceService raySourceService,
|
||||
ILogger logger)
|
||||
ILoggerService logger)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(raySourceService);
|
||||
ArgumentNullException.ThrowIfNull(logger);
|
||||
|
||||
_raySourceService = raySourceService;
|
||||
_logger = logger;
|
||||
_logger = logger.ForModule<AppStateService>();
|
||||
_dispatcher = Application.Current.Dispatcher;
|
||||
|
||||
SubscribeToExistingServices();
|
||||
_logger.Information("AppStateService 已初始化");
|
||||
_logger.Info("AppStateService 已初始化");
|
||||
}
|
||||
|
||||
// ── 状态更新方法 ──
|
||||
@@ -71,7 +71,7 @@ namespace XplorePlane.Services.AppState
|
||||
public void UpdateMotionState(MotionState newState)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(newState);
|
||||
if (_disposed) { _logger.Warning("AppStateService 已释放,忽略 UpdateMotionState 调用"); return; }
|
||||
if (_disposed) { _logger.Warn("AppStateService 已释放,忽略 UpdateMotionState 调用"); return; }
|
||||
|
||||
var old = Interlocked.Exchange(ref _motionState, newState);
|
||||
if (ReferenceEquals(old, newState)) return;
|
||||
@@ -81,7 +81,7 @@ namespace XplorePlane.Services.AppState
|
||||
public void UpdateRaySourceState(RaySourceState newState)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(newState);
|
||||
if (_disposed) { _logger.Warning("AppStateService 已释放,忽略 UpdateRaySourceState 调用"); return; }
|
||||
if (_disposed) { _logger.Warn("AppStateService 已释放,忽略 UpdateRaySourceState 调用"); return; }
|
||||
|
||||
var old = Interlocked.Exchange(ref _raySourceState, newState);
|
||||
if (ReferenceEquals(old, newState)) return;
|
||||
@@ -91,7 +91,7 @@ namespace XplorePlane.Services.AppState
|
||||
public void UpdateDetectorState(DetectorState newState)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(newState);
|
||||
if (_disposed) { _logger.Warning("AppStateService 已释放,忽略 UpdateDetectorState 调用"); return; }
|
||||
if (_disposed) { _logger.Warn("AppStateService 已释放,忽略 UpdateDetectorState 调用"); return; }
|
||||
|
||||
var old = Interlocked.Exchange(ref _detectorState, newState);
|
||||
if (ReferenceEquals(old, newState)) return;
|
||||
@@ -101,7 +101,7 @@ namespace XplorePlane.Services.AppState
|
||||
public void UpdateSystemState(SystemState newState)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(newState);
|
||||
if (_disposed) { _logger.Warning("AppStateService 已释放,忽略 UpdateSystemState 调用"); return; }
|
||||
if (_disposed) { _logger.Warn("AppStateService 已释放,忽略 UpdateSystemState 调用"); return; }
|
||||
|
||||
var old = Interlocked.Exchange(ref _systemState, newState);
|
||||
if (ReferenceEquals(old, newState)) return;
|
||||
@@ -111,7 +111,7 @@ namespace XplorePlane.Services.AppState
|
||||
public void UpdateCameraState(CameraState newState)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(newState);
|
||||
if (_disposed) { _logger.Warning("AppStateService 已释放,忽略 UpdateCameraState 调用"); return; }
|
||||
if (_disposed) { _logger.Warn("AppStateService 已释放,忽略 UpdateCameraState 调用"); return; }
|
||||
|
||||
var old = Interlocked.Exchange(ref _cameraState, newState);
|
||||
if (ReferenceEquals(old, newState)) return;
|
||||
@@ -121,7 +121,7 @@ namespace XplorePlane.Services.AppState
|
||||
public void UpdateCalibrationMatrix(CalibrationMatrix newMatrix)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(newMatrix);
|
||||
if (_disposed) { _logger.Warning("AppStateService 已释放,忽略 UpdateCalibrationMatrix 调用"); return; }
|
||||
if (_disposed) { _logger.Warn("AppStateService 已释放,忽略 UpdateCalibrationMatrix 调用"); return; }
|
||||
|
||||
var old = Interlocked.Exchange(ref _calibrationMatrix, newMatrix);
|
||||
if (ReferenceEquals(old, newMatrix)) return;
|
||||
@@ -135,7 +135,7 @@ namespace XplorePlane.Services.AppState
|
||||
public void UpdateLinkedViewState(LinkedViewState newState)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(newState);
|
||||
if (_disposed) { _logger.Warning("AppStateService 已释放,忽略 UpdateLinkedViewState 调用"); return; }
|
||||
if (_disposed) { _logger.Warn("AppStateService 已释放,忽略 UpdateLinkedViewState 调用"); return; }
|
||||
|
||||
var old = Interlocked.Exchange(ref _linkedViewState, newState);
|
||||
if (ReferenceEquals(old, newState)) return;
|
||||
@@ -145,7 +145,7 @@ namespace XplorePlane.Services.AppState
|
||||
public void UpdateRecipeExecutionState(RecipeExecutionState newState)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(newState);
|
||||
if (_disposed) { _logger.Warning("AppStateService 已释放,忽略 UpdateRecipeExecutionState 调用"); return; }
|
||||
if (_disposed) { _logger.Warn("AppStateService 已释放,忽略 UpdateRecipeExecutionState 调用"); return; }
|
||||
|
||||
var old = Interlocked.Exchange(ref _recipeExecutionState, newState);
|
||||
if (ReferenceEquals(old, newState)) return;
|
||||
@@ -159,7 +159,7 @@ namespace XplorePlane.Services.AppState
|
||||
var matrix = _calibrationMatrix;
|
||||
if (matrix is null)
|
||||
{
|
||||
_logger.Warning("CalibrationMatrix 未设置,无法执行画面联动 (pixelX={PixelX}, pixelY={PixelY})", pixelX, pixelY);
|
||||
_logger.Warn("CalibrationMatrix 未设置,无法执行画面联动 (pixelX={PixelX}, pixelY={PixelY})", pixelX, pixelY);
|
||||
UpdateSystemState(SystemState with
|
||||
{
|
||||
HasError = true,
|
||||
@@ -203,10 +203,7 @@ namespace XplorePlane.Services.AppState
|
||||
|
||||
private void SubscribeToExistingServices()
|
||||
{
|
||||
// IRaySourceService 是基于命令的服务(没有直接的状态变更事件),
|
||||
// 状态同步由外部调用者通过 UpdateRaySourceState 完成。
|
||||
// TODO: 当 IRaySourceService 添加状态变更事件时,在此处订阅并同步到 RaySourceState
|
||||
_logger.Information("AppStateService 已准备好接收外部服务状态更新");
|
||||
_logger.Info("AppStateService 已准备好接收外部服务状态更新");
|
||||
}
|
||||
|
||||
// ── Dispose ──
|
||||
@@ -226,7 +223,7 @@ namespace XplorePlane.Services.AppState
|
||||
RecipeExecutionStateChanged = null;
|
||||
LinkedViewRequested = null;
|
||||
|
||||
_logger.Information("AppStateService 已释放");
|
||||
_logger.Info("AppStateService 已释放");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,19 +8,19 @@ using Emgu.CV;
|
||||
using Emgu.CV.Structure;
|
||||
using ImageProcessing.Core;
|
||||
using ImageProcessing.Processors;
|
||||
using Serilog;
|
||||
using XP.Common.Logging.Interfaces;
|
||||
|
||||
namespace XplorePlane.Services
|
||||
{
|
||||
public class ImageProcessingService : IImageProcessingService
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ILoggerService _logger;
|
||||
private readonly ConcurrentDictionary<string, ImageProcessorBase> _processorRegistry;
|
||||
private readonly ConcurrentDictionary<string, ImageProcessorBase16> _processorRegistry16;
|
||||
|
||||
public ImageProcessingService(ILogger logger)
|
||||
public ImageProcessingService(ILoggerService logger)
|
||||
{
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
_logger = logger?.ForModule<ImageProcessingService>() ?? throw new ArgumentNullException(nameof(logger));
|
||||
_processorRegistry = new ConcurrentDictionary<string, ImageProcessorBase>();
|
||||
_processorRegistry16 = new ConcurrentDictionary<string, ImageProcessorBase16>();
|
||||
RegisterBuiltInProcessors();
|
||||
@@ -43,7 +43,7 @@ namespace XplorePlane.Services
|
||||
_processorRegistry16["GaussianBlur16"] = new GaussianBlurProcessor16();
|
||||
_processorRegistry16["FlatFieldCorrection16"] = new FlatFieldCorrectionProcessor16();
|
||||
|
||||
_logger.Information("Registered {Count8} 8-bit and {Count16} 16-bit built-in image processors",
|
||||
_logger.Info("Registered {Count8} 8-bit and {Count16} 16-bit built-in image processors",
|
||||
_processorRegistry.Count, _processorRegistry16.Count);
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace XplorePlane.Services
|
||||
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("Processor name cannot be empty", nameof(name));
|
||||
if (processor == null) throw new ArgumentNullException(nameof(processor));
|
||||
_processorRegistry[name] = processor;
|
||||
_logger.Information("Registered processor: {ProcessorName}", name);
|
||||
_logger.Info("Registered processor: {ProcessorName}", name);
|
||||
}
|
||||
|
||||
public IReadOnlyList<ProcessorParameter> GetProcessorParameters(string processorName)
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.IO;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Serilog;
|
||||
using XP.Common.Logging.Interfaces;
|
||||
using XplorePlane.Models;
|
||||
using XplorePlane.Services.AppState;
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace XplorePlane.Services.Recipe
|
||||
{
|
||||
private readonly IAppStateService _appStateService;
|
||||
private readonly IPipelineExecutionService _pipelineExecutionService;
|
||||
private readonly ILogger _logger;
|
||||
private readonly ILoggerService _logger;
|
||||
private readonly ManualResetEventSlim _pauseHandle = new(true); // initially signaled (not paused)
|
||||
|
||||
private static readonly JsonSerializerOptions _jsonOptions = new()
|
||||
@@ -29,7 +29,7 @@ namespace XplorePlane.Services.Recipe
|
||||
public RecipeService(
|
||||
IAppStateService appStateService,
|
||||
IPipelineExecutionService pipelineExecutionService,
|
||||
ILogger logger)
|
||||
ILoggerService logger)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(appStateService);
|
||||
ArgumentNullException.ThrowIfNull(pipelineExecutionService);
|
||||
@@ -37,9 +37,9 @@ namespace XplorePlane.Services.Recipe
|
||||
|
||||
_appStateService = appStateService;
|
||||
_pipelineExecutionService = pipelineExecutionService;
|
||||
_logger = logger;
|
||||
_logger = logger.ForModule<RecipeService>();
|
||||
|
||||
_logger.Information("RecipeService 已初始化");
|
||||
_logger.Info("RecipeService 已初始化");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -55,7 +55,7 @@ namespace XplorePlane.Services.Recipe
|
||||
UpdatedAt: DateTime.UtcNow,
|
||||
Steps: new List<RecipeStep>().AsReadOnly());
|
||||
|
||||
_logger.Information("已创建配方: {RecipeName}, Id={RecipeId}", name, recipe.Id);
|
||||
_logger.Info("已创建配方: {RecipeName}, Id={RecipeId}", name, recipe.Id);
|
||||
return recipe;
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace XplorePlane.Services.Recipe
|
||||
DetectorState: detectorState,
|
||||
Pipeline: pipeline);
|
||||
|
||||
_logger.Information("已记录配方步骤: StepIndex={StepIndex}, Recipe={RecipeName}",
|
||||
_logger.Info("已记录配方步骤: StepIndex={StepIndex}, Recipe={RecipeName}",
|
||||
step.StepIndex, recipe.Name);
|
||||
return step;
|
||||
}
|
||||
@@ -94,7 +94,7 @@ namespace XplorePlane.Services.Recipe
|
||||
var json = JsonSerializer.Serialize(recipe, _jsonOptions);
|
||||
await File.WriteAllTextAsync(filePath, json).ConfigureAwait(false);
|
||||
|
||||
_logger.Information("已保存配方到文件: {FilePath}, Recipe={RecipeName}", filePath, recipe.Name);
|
||||
_logger.Info("已保存配方到文件: {FilePath}, Recipe={RecipeName}", filePath, recipe.Name);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -134,7 +134,7 @@ namespace XplorePlane.Services.Recipe
|
||||
if (recipe.Steps is null)
|
||||
throw new InvalidDataException($"配方文件数据不完整,缺少步骤列表: {filePath}");
|
||||
|
||||
_logger.Information("已加载配方: {FilePath}, Recipe={RecipeName}, Steps={StepCount}",
|
||||
_logger.Info("已加载配方: {FilePath}, Recipe={RecipeName}, Steps={StepCount}",
|
||||
filePath, recipe.Name, recipe.Steps.Count);
|
||||
return recipe;
|
||||
}
|
||||
@@ -144,7 +144,7 @@ namespace XplorePlane.Services.Recipe
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(recipe);
|
||||
|
||||
_logger.Information("开始执行配方: {RecipeName}, 共 {StepCount} 步", recipe.Name, recipe.Steps.Count);
|
||||
_logger.Info("开始执行配方: {RecipeName}, 共 {StepCount} 步", recipe.Name, recipe.Steps.Count);
|
||||
|
||||
// 重置暂停状态
|
||||
_pauseHandle.Set();
|
||||
@@ -172,7 +172,7 @@ namespace XplorePlane.Services.Recipe
|
||||
Status: RecipeExecutionStatus.Running,
|
||||
CurrentRecipeName: recipe.Name));
|
||||
|
||||
_logger.Information("执行配方步骤 {StepIndex}/{TotalSteps}: Recipe={RecipeName}",
|
||||
_logger.Info("执行配方步骤 {StepIndex}/{TotalSteps}: Recipe={RecipeName}",
|
||||
i + 1, recipe.Steps.Count, recipe.Name);
|
||||
|
||||
try
|
||||
@@ -208,11 +208,11 @@ namespace XplorePlane.Services.Recipe
|
||||
Status: RecipeExecutionStatus.Completed,
|
||||
CurrentRecipeName: recipe.Name));
|
||||
|
||||
_logger.Information("配方执行完成: {RecipeName}", recipe.Name);
|
||||
_logger.Info("配方执行完成: {RecipeName}", recipe.Name);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
_logger.Information("配方执行已取消: {RecipeName}", recipe.Name);
|
||||
_logger.Info("配方执行已取消: {RecipeName}", recipe.Name);
|
||||
|
||||
_appStateService.UpdateRecipeExecutionState(new RecipeExecutionState(
|
||||
CurrentStepIndex: 0,
|
||||
@@ -238,7 +238,7 @@ namespace XplorePlane.Services.Recipe
|
||||
});
|
||||
}
|
||||
|
||||
_logger.Information("配方执行已暂停");
|
||||
_logger.Info("配方执行已暂停");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -254,7 +254,7 @@ namespace XplorePlane.Services.Recipe
|
||||
}
|
||||
|
||||
_pauseHandle.Set();
|
||||
_logger.Information("配方执行已恢复");
|
||||
_logger.Info("配方执行已恢复");
|
||||
}
|
||||
|
||||
// ── 内部辅助方法 ──
|
||||
@@ -271,9 +271,7 @@ namespace XplorePlane.Services.Recipe
|
||||
_appStateService.UpdateDetectorState(step.DetectorState);
|
||||
|
||||
// TODO: 通过 IPipelineExecutionService 执行 Pipeline
|
||||
// IPipelineExecutionService.ExecutePipelineAsync 需要 IEnumerable<PipelineNodeViewModel> 和 BitmapSource,
|
||||
// 而 RecipeStep 持有 PipelineModel。此处记录日志作为占位,待 ViewModel 层适配后完善。
|
||||
_logger.Information("步骤 {StepIndex}: 已更新设备状态,Pipeline '{PipelineName}' 执行待实现",
|
||||
_logger.Info("步骤 {StepIndex}: 已更新设备状态,Pipeline '{PipelineName}' 执行待实现",
|
||||
step.StepIndex, step.Pipeline?.Name ?? "N/A");
|
||||
|
||||
await Task.CompletedTask;
|
||||
|
||||
Reference in New Issue
Block a user