using System.Text.RegularExpressions; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using WIDESEAWCS_Core; using WIDESEAWCS_Core.BaseController; using WIDESEAWCS_ITaskInfoService; using WIDESEAWCS_Model.Models; namespace WIDESEAWCS_WCSServer.Controllers.Task { [Route("api/Task_Hty")] [ApiController] public class Task_HtyController : ApiBaseController { private readonly IHttpContextAccessor _httpContextAccessor; public Task_HtyController(ITask_HtyService service, IHttpContextAccessor httpContextAccessor) : base(service) { _httpContextAccessor = httpContextAccessor; } [HttpGet, Route("Test")] public WebResponseContent Test() { var pattern = @"\u0002\[([^\]]+)\] \[([^\]]+)\](?: \[([^\]]+)\])?(?: ([^\u0003]*?))?(?:\n\[异常\]([\s\S]*?))?\u0003"; Regex.Match("\u0002[2025-09-17 16:40:11.180] [ERROR] CommonStackerCraneJob Start{\"LogKey\":null}\u0003", pattern); var temp = Regex.Matches("\u0002[2025-09-17 16:40:11.180] [ERROR] CommonStackerCraneJob Start{\"LogKey\":null}\u0003", pattern); List matches = temp.ToList(); for (int i = 0; i < matches.Count; i++) { Match match = matches[i]; if (match.Success) { var timestamp = match.Groups[1].Value; var logLevel = match.Groups[2].Value; var keyword = match.Groups[3].Value; // 可能为空 var message = match.Groups[4].Value; // 可能为空 var exception = match.Groups[5].Value; // 可能为空 } } return WebResponseContent.Instance.OK(); } } }