Files

94 lines
3.6 KiB
C#
Raw Permalink Normal View History

2026-07-14 13:55:17 +08:00
using JY.Utility;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI.WebControls;
namespace JY.Inspection.Mes
{
public interface IMesLog
{
void LogProductResult(DateTime curTime, string reqJsonStr, string respMes, long costTime);
void LogArrivalStation(DateTime curTime, string reqJsonStr, string respMes, long costTime);
void LogExitStation(DateTime curTime, string reqJsonStr, string respMes, long costTime);
2026-07-15 15:21:17 +08:00
void LogLoginMes(DateTime curTime, string reqJsonStr, string respMes, long costTime);
2026-07-28 10:51:38 +08:00
void LogEqupAlarmInfo(DateTime curTime, string reqJsonStr, string respMes, long costTime);
2026-07-28 15:43:17 +08:00
void LogEqupStatus(DateTime curTime, string reqJsonStr, string respMes, long costTime);
2026-07-14 13:55:17 +08:00
}
public class MesLog : IMesLog
{
private void LogoutAction(string actionName, DateTime curTime, string reqJsonStr, string respMes, long costTime)
{
// 构建日志目录和文件路径
string mesLogPath = @"D:\APILog\MesLogs";
string logDate = curTime.ToString("yyyyMMdd");
string logHour = curTime.ToString("HH");
string logDirectory = Path.Combine(mesLogPath, logDate, actionName);
string logFilePath = Path.Combine(logDirectory, $"{logHour}.txt");
// 确保目录存在
Directory.CreateDirectory(logDirectory);
// 使用StringBuilder构建日志消息
var logBuilder = new StringBuilder();
logBuilder.AppendLine($"{curTime.ToString("yyyy-MM-dd HH:mm:ss.fff")}:{actionName}接口:{Global.systemConfig.ResultProcessMesUrl}");
logBuilder.AppendLine($"请求数据为:{reqJsonStr}");
logBuilder.AppendLine($"{curTime.AddMilliseconds(costTime).ToString("yyyy-MM-dd HH:mm:ss.fff")}:接口耗时:{costTime}ms");
logBuilder.AppendLine($"返回结果:{respMes}");
// 写入日志文件
TxtHelper.WriteTxt(logFilePath, logBuilder.ToString());
}
public void LogArrivalStation(DateTime curTime, string reqJsonStr, string respMes, long costTime)
{
string actionName = "产品入站";
LogoutAction(actionName, curTime, reqJsonStr, respMes, costTime);
}
public void LogExitStation(DateTime curTime, string reqJsonStr, string respMes, long costTime)
{
string actionName = "产品出站";
LogoutAction(actionName, curTime, reqJsonStr, respMes, costTime);
}
public void LogProductResult(DateTime curTime, string reqJsonStr, string respMes, long costTime)
{
string actionName = "产品结果加工参数";
LogoutAction(actionName, curTime, reqJsonStr, respMes, costTime);
}
2026-07-15 15:21:17 +08:00
public void LogLoginMes(DateTime curTime, string reqJsonStr, string respMes, long costTime)
{
string actionName = "Mes员工登录";
LogoutAction(actionName, curTime, reqJsonStr, respMes, costTime);
}
2026-07-28 10:51:38 +08:00
public void LogEqupAlarmInfo(DateTime curTime, string reqJsonStr, string respMes, long costTime)
{
string actionName = "设备报警";
LogoutAction(actionName, curTime, reqJsonStr, respMes, costTime);
}
2026-07-28 15:43:17 +08:00
public void LogEqupStatus(DateTime curTime, string reqJsonStr, string respMes, long costTime)
{
string actionName = "设备状态";
LogoutAction(actionName, curTime, reqJsonStr, respMes, costTime);
}
2026-07-14 13:55:17 +08:00
}
}