using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common.LogEnum;
namespace WIDESEA_Core.Utilities
{
public class LogRecord
{
///
/// 日志记录
///
/// 1=入库 2=出库 3=盘点 4=行车
///
///
public static void WriteLog(LogEnum type ,string content, string stacker = null)
{
string filename = DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
if(stacker != null)
filename = DateTime.Now.ToString("yyyy-MM-dd-") + stacker + ".txt";
string month = DateTime.Now.Year.ToString() + "年" + DateTime.Now.Month.ToString() + "月";
string dir = "D:\\WCS_log\\InBound\\"+ month +"\\"+ DateTime.Now.ToString("yyyy-MM-dd")+"\\";
if(type == LogEnum.OutBound)
dir = "D:\\WCS_log\\OutBound\\" + month + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
else if(type == LogEnum.AGV)
dir = "D:\\WCS_log\\AGV\\" + month + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
else if (type == LogEnum.RGV)
dir = "D:\\WCS_log\\RGV\\" + month + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
else if(type == LogEnum.System)
dir = "D:\\WCS_log\\System\\" + month + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
StackTrace trace = new StackTrace();
StackFrame frame = trace.GetFrame(1); //1代表上级,2代表上上级,以此类推
MethodBase method = frame.GetMethod();
string methodName = method.Name;
string className = method.ReflectedType.FullName;
string resultstr = DateTime.Now.ToString("【yyyy-MM-dd HH:mm:ss.fff】") + "===>" + content;
if (string.IsNullOrEmpty(content))
resultstr = "\r\n\r\n";
FileHelper.WriteLog(dir, filename, resultstr + "\r\n");
}
}
}