Commit a8d6bd04 LN

日志打印修改

1 个父辈 7f50a6a4
......@@ -177,7 +177,7 @@ namespace OnlineStore.Common
}
catch (Exception Ex)
{
LogUtil.error(LOGGER, Ex.ToString());
LogUtil.error(Ex.ToString());
//throw Ex;
}
return ok;
......@@ -268,7 +268,7 @@ namespace OnlineStore.Common
// catch (Exception ex)
// {
// _serialPort.DiscardOutBuffer();
// LogUtil.error(LOGGER, "SendData ERROR:" + ex.ToString(), 21);
// LogUtil.error( "SendData ERROR:" + ex.ToString(), 21);
// }
// }
......@@ -323,7 +323,7 @@ namespace OnlineStore.Common
catch (Exception ex)
{
isOk = false;
LogUtil.error(LOGGER, "SendCommand ERROR:" + ex.ToString(), 20);
LogUtil.error( "SendCommand ERROR:" + ex.ToString(), 20);
}
finally
{
......
......@@ -85,11 +85,11 @@ namespace OnlineStore.Common
catch (WebException ex)
{
IsTimeOut = true;
LogUtil.error(LOGGER, "POST WebException :" + ex.ToString(), 101);
LogUtil.error( "POST WebException :" + ex.ToString(), 101);
}
catch (Exception e)
{
LogUtil.error(LOGGER, "POST ERROR:" + e.ToString(), 1);
LogUtil.error( "POST ERROR:" + e.ToString(), 1);
}
if (isLog == 1)
{
......@@ -151,7 +151,7 @@ namespace OnlineStore.Common
}
if (!result.Contains("null") && result.Length != 0)
{
//LogUtil.debug(LOGGER,"receive << " + result);
//LogUtil.debug( "receive << " + result);
}
if (isLog == 1)
{
......
......@@ -6,6 +6,7 @@ using log4net;
using System.Reflection;
using System.Drawing;
using System.Runtime.ExceptionServices;
using System.Threading;
namespace OnlineStore.Common
{
......@@ -13,112 +14,122 @@ namespace OnlineStore.Common
{
public static readonly ILog AIOLog = LogManager.GetLogger("AIOBOXLog");
private static LogUtil instance = new LogUtil();
public delegate void ShowLog(string msg, Color color);
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public delegate void ShowLog(string msg, Color color);
public static readonly ILog LOGGER = LogManager.GetLogger("RollingLogFileAppender");
public static readonly ILog rfidLog = LogManager.GetLogger("RfidLog");
public static Dictionary<int, DateTime> lastErrorLogTime = new Dictionary<int, DateTime>();
public static System.Windows.Forms.RichTextBox logBox = null;
public static int showCount = 10;
public static int showCount = 15;
public static bool debug_opened = false;
public static void info(ILog log,string msg )
public static void info(ILog log, string msg)
{
if (log == null)
{
return;
}
log.Info( msg);
AddToBox(msg, Color.Black);
log.Info(msg);
AddToBox(msg, Color.Black);
//clear();
}
public static void info(ILog log,string msg, Color color)
public static void info(ILog log, string msg, Color color)
{
log.Info( msg);
AddToBox(msg, color);
log.Info(msg);
AddToBox(msg, color);
}
public static void debug(ILog log, string msg, Color color)
{
log.Debug( msg);
log.Debug(msg);
if (debug_opened)
{
{
AddToBox(msg, color);
}
}
public static void debug(ILog log, string msg)
{
log.Debug( msg);
log.Debug(msg);
if (debug_opened)
{
AddToBox(msg, Color.Gray);
{
AddToBox(msg, Color.Gray);
}
}
private static List<string> lasErrorLogList = new List<string>();
private static int errCount = 5;
public static void error(ILog log, string errorMsg,int type,int spanSeconds=10)
public static void error(string errorMsg, int type, int seconds = 10)
{
if (lastErrorLogTime.ContainsKey(type))
try
{
try
if (lastErrorLogTime.ContainsKey(type))
{
TimeSpan span = DateTime.Now - lastErrorLogTime[type];
if (span.TotalSeconds < spanSeconds)
{
return;
}
else
if (span.TotalSeconds > seconds)
{
lastErrorLogTime.Remove(type);
lastErrorLogTime.Add(type, DateTime.Now);
error(log, errorMsg);
error(LOGGER, errorMsg);
}
}catch(Exception ex)
}
else
{
lastErrorLogTime.Add(type, DateTime.Now);
error(LOGGER, errorMsg);
}
}
else
catch (Exception ex)
{
lastErrorLogTime.Add(type, DateTime.Now);
error(log, errorMsg);
LOGGER.Error(" 打印日志【" + type + "-" + errorMsg + "】出错:" + ex.ToString());
}
}
public static void error(ILog log, string errorMsg)
public static void error(ILog log, string errorMsg, Exception ex = null)
{
log.Error( errorMsg);
if (errorMsg.Trim().Equals("") && (ex == null))
{
return;
}
if (ex == null)
{
log.Error(errorMsg);
}
else
{
log.Error(errorMsg, ex);
}
AddToBox(errorMsg, Color.Red);
}
private static object lockObj = "";
private static void AddToBox(string msg, Color color)
{
try
{
ShowLogPro(msg, color);
if (Monitor.TryEnter(lockObj, 2))
{
try
{
ShowLogPro(msg, color);
}
catch (Exception ex)
{
LOGGER.Error("出错:", ex);
}
finally
{
Monitor.Exit(lockObj);
}
}
catch (Exception ex)
else
{
LOGGER.Error("出错:" + ex.StackTrace);
}
LOGGER.Debug("ShowLogPro【" + msg + "】失败,未得到锁");
}
}
private static List<string> logList = new List<string>();
public static string LastText = "";
[HandleProcessCorruptedStateExceptions]
private static void ShowLogPro(string msg, Color color)
{
try
{
if (logList.Count > 0)
{
// logList.RemoveAt(0);
}
if (logList.Count >= showCount)
{
logList.RemoveAt(0);
......@@ -143,7 +154,7 @@ namespace OnlineStore.Common
logBox.AppendText(now.ToLongTimeString() + " " + msg + Environment.NewLine); //增加文本
TimeSpan span = DateTime.Now - lastTime;
if (span.TotalSeconds > 1000)
if (span.TotalSeconds > 3000)
{
lastTime = DateTime.Now;
logBox.Select(logBox.Text.Length, 0); //设置光标的位置到文本尾
......@@ -153,7 +164,7 @@ namespace OnlineStore.Common
}
catch (AccessViolationException e)
{
LOGGER.Error( " ShowLogPro 出错:" + e.ToString());
LOGGER.Error(" ShowLogPro 出错:" + e.ToString());
}
catch (Exception ex)
{
......@@ -165,7 +176,15 @@ namespace OnlineStore.Common
{
if (logBox != null && logBox.Visible)
{
logBox.Text = LastText;
logBox.Text = LastText;
TimeSpan span = DateTime.Now - lastTime;
if (span.TotalSeconds > 3000000)
{
lastTime = DateTime.Now;
logBox.Select(logBox.Text.Length, 0); //设置光标的位置到文本尾
logBox.ScrollToCaret(); //滚动到控件光标处
}
}
}
public static void ClearLog()
......@@ -182,17 +201,14 @@ namespace OnlineStore.Common
{
debug(LOGGER, msg);
}
public static void error(string errorMsg)
public static void error(string errorMsg, Exception ex = null)
{
error( LOGGER,errorMsg);
error(LOGGER, errorMsg, ex);
}
public static void info(string msg)
{
info(LOGGER,msg );
}
info(LOGGER, msg);
}
}
}
......@@ -123,7 +123,7 @@ namespace OnlineStore.Common
}
catch (Exception ex)
{
LogUtil.error(LOGGER,"Connect to " + serverIP + ":" + serverPort + " fail!" + ex.ToString(),3);
LogUtil.error("Connect to " + serverIP + ":" + serverPort + " fail!" + ex.ToString(),3);
m_clientSocket = null;
}
......@@ -176,7 +176,7 @@ namespace OnlineStore.Common
catch (Exception ex)
{
isInProcess = false;
LogUtil.error(LOGGER, "重连处理出错:" + ex.ToString(),9,180);
LogUtil.error( "重连处理出错:" + ex.ToString(),9,180);
}
}
......@@ -227,7 +227,7 @@ namespace OnlineStore.Common
}
catch (Exception ex)
{
LogUtil.error(LOGGER,"socket received error:" + ex.ToString(),4);
LogUtil.error("socket received error:" + ex.ToString(),4);
}
}
}
......
......@@ -39,7 +39,7 @@ namespace OnlineStore.Common
}
}
}
LogUtil.info(LOGGER, iplist + "]");
LogUtil.info( iplist + "]");
}
/// <summary>
......@@ -59,7 +59,7 @@ namespace OnlineStore.Common
m_serverThread = new Thread(new ThreadStart(ReceiveAccept));
m_serverThread.Start();
LogUtil.info(LOGGER, " Server start listen : " + m_serverPort);
LogUtil.info( " Server start listen : " + m_serverPort);
logLocalIp();
//this.AddRunningInfo(">> " + DateTime.Now.ToString() + " Server started.");
......@@ -101,14 +101,14 @@ namespace OnlineStore.Common
client.ClientSocket = m_serverSocket.Accept();
IPEndPoint clientipe = (IPEndPoint)client.ClientSocket.RemoteEndPoint;
client.ipAdd = clientipe.Address;
LogUtil.info(LOGGER, "有新的客户端链接上:" + client.ipAdd.ToString());
LogUtil.info( "有新的客户端链接上:" + client.ipAdd.ToString());
receiveMessageDelegate = new ReceiveMessageDelegate(ReceiveMessages);
receiveMessageDelegate.BeginInvoke(client, ReceiveMessagesCallback, "");
}
catch (Exception ex)
{
LogUtil.error(LOGGER, ex.Message);
LogUtil.error( ex.Message);
//throw new Exception(ex.Message);
}
}
......@@ -158,11 +158,11 @@ namespace OnlineStore.Common
}
catch (SocketException e)
{
LogUtil.error(LOGGER, e.ToString(), 6);
LogUtil.error( e.ToString(), 6);
}
catch (Exception ex)
{
LogUtil.error(LOGGER, ex.ToString(), 5);
LogUtil.error( ex.ToString(), 5);
}
}
//private void ReceiveMessages(Client client)
......@@ -180,10 +180,10 @@ namespace OnlineStore.Common
// if (!string.IsNullOrEmpty(strReceiveData))
// {
// LogUtil.info(LOGGER, "收到数据:" + strReceiveData);
// LogUtil.info( "收到数据:" + strReceiveData);
// // this.AddRunningInfo(">> Receive data from [" + client.ClientSocket.RemoteEndPoint.ToString()+ "]:" + strReceiveData);
// string strSendData = "OK. The content is:" + strReceiveData;
// //LogUtil.info(LOGGER, "OK. The content is:" + strReceiveData);
// //LogUtil.info( "OK. The content is:" + strReceiveData);
// int sendBufferSize = Encoding.Unicode.GetByteCount(strSendData);
// byte[] sendBuffer = new byte[sendBufferSize];
// sendBuffer = Encoding.Unicode.GetBytes(strSendData);
......@@ -194,7 +194,7 @@ namespace OnlineStore.Common
// }
// catch (SocketException e)
// {
// LogUtil.error(LOGGER, e.ToString());
// LogUtil.error( e.ToString());
// }
// catch (Exception ex)
// {
......
......@@ -50,7 +50,7 @@ namespace OnlineStore.DeviceLibrary
ACStorePosition position = param.GetACPosition();
if (position == null)
{
LogUtil.error(LOGGER, StoreName + "出入库时发现param中取到的Position=null,没有库位不能执行出入库");
LogUtil.error( StoreName + "出入库时发现param中取到的Position=null,没有库位不能执行出入库");
return false;
}
......@@ -91,7 +91,7 @@ namespace OnlineStore.DeviceLibrary
ACStorePosition position = param.GetACPosition();
if (position == null)
{
LogUtil.error(LOGGER, StoreName + "出入库时发现param中取到的Position=null,没有库位不能执行出入库");
LogUtil.error( StoreName + "出入库时发现param中取到的Position=null,没有库位不能执行出入库");
return false;
}
if (param.PosInfo.PlateH <= 0)
......@@ -195,7 +195,7 @@ namespace OnlineStore.DeviceLibrary
}
Alarm(StoreAlarmType.IoSingleTimeOut, io.ElectricalDefinition, WarnMsg, StoreMove.MoveType);
LogUtil.error(LOGGER, StoreName + wait.IoType + "等待信号(" + io.DisplayStr + "=" + wait.IoValue + ") 超时", 14);
LogUtil.error( StoreName + wait.IoType + "等待信号(" + io.DisplayStr + "=" + wait.IoValue + ") 超时", 14);
isOk = false;
break;
}
......@@ -271,7 +271,7 @@ namespace OnlineStore.DeviceLibrary
return;
}
LogUtil.error(LOGGER, WarnMsg,100);
LogUtil.error( WarnMsg,100);
Alarm(StoreAlarmType.IoSingleTimeOut, "", WarnMsg, StoreMove.MoveType);
}
}
......@@ -295,12 +295,12 @@ namespace OnlineStore.DeviceLibrary
{
if (!LoadParamPosition(param))
{
LogUtil.error(LOGGER, StoreName + " 启动入库【" + posId + "】出错,找不到库位信息");
LogUtil.error( StoreName + " 启动入库【" + posId + "】出错,找不到库位信息");
return;
}
if (IOManager.IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH))
{
LogUtil.error(LOGGER, StoreName + " 启动入库【" + posId + "】出错,叉子料盘检测有料");
LogUtil.error( StoreName + " 启动入库【" + posId + "】出错,叉子料盘检测有料");
return;
}
LogUtil.info(LOGGER, StoreName + " 启动入库【" + posId + "】", storeMoveColor);
......@@ -329,7 +329,7 @@ namespace OnlineStore.DeviceLibrary
}
else
{
LogUtil.error(LOGGER, StoreName + " 启动【" + posId + "】入库出错,当前状态,storeStatus=" + storeRunStatus);
LogUtil.error( StoreName + " 启动【" + posId + "】入库出错,当前状态,storeStatus=" + storeRunStatus);
}
}
......@@ -407,7 +407,7 @@ namespace OnlineStore.DeviceLibrary
}
WarnMsg = StoreName + "入库 等待料仓门口检测到料盘 [" + StoreMove.MoveParam.PosInfo.barcode + "] [" + StoreMove.MoveParam.PosInfo.PosId + "] 超时 [" + Math.Round(StoreMove.StepSpan().TotalSeconds, 1) + "]秒 ";
LogUtil.error(LOGGER, WarnMsg, 100);
LogUtil.error( WarnMsg, 100);
Alarm(StoreAlarmType.IoSingleTimeOut, "", WarnMsg, StoreMove.MoveType);
}
}
......@@ -591,12 +591,12 @@ namespace OnlineStore.DeviceLibrary
{
if (!LoadParamPosition(param))
{
LogUtil.error(LOGGER, StoreName + " 启动出库【" + posId + "】出错,找不到库位信息");
LogUtil.error( StoreName + " 启动出库【" + posId + "】出错,找不到库位信息");
return false;
}
if (IOManager.IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH))
{
LogUtil.error(LOGGER, StoreName + " 启动出库【" + posId + "】出错,叉子料盘检测有料");
LogUtil.error( StoreName + " 启动出库【" + posId + "】出错,叉子料盘检测有料");
return false;
}
storeStatus = StoreStatus.OutStoreExecute;
......@@ -612,7 +612,7 @@ namespace OnlineStore.DeviceLibrary
}
else
{
LogUtil.error(LOGGER, StoreName + " 启动出库出错,当前状态,storeStatus=" + storeRunStatus);
LogUtil.error( StoreName + " 启动出库出错,当前状态,storeStatus=" + storeRunStatus);
}
return false;
}
......@@ -873,7 +873,7 @@ namespace OnlineStore.DeviceLibrary
}
else
{
LogUtil.error(LOGGER, StoreName + " 出库处理,moveStatus=" + StoreMove.MoveStep + ",没有对应的处理!");
LogUtil.error( StoreName + " 出库处理,moveStatus=" + StoreMove.MoveStep + ",没有对应的处理!");
}
}
......@@ -1115,7 +1115,7 @@ namespace OnlineStore.DeviceLibrary
}
catch (Exception ex)
{
LogUtil.error(LOGGER, ex.ToString());
LogUtil.error( ex.ToString());
}
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!