添加项目文件。
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user