Commit 4fdbf97d LN

日志修改

1 个父辈 7073b288
...@@ -187,6 +187,7 @@ ...@@ -187,6 +187,7 @@
this.logBox.Size = new System.Drawing.Size(1316, 588); this.logBox.Size = new System.Drawing.Size(1316, 588);
this.logBox.TabIndex = 106; this.logBox.TabIndex = 106;
this.logBox.Text = ""; this.logBox.Text = "";
this.logBox.VisibleChanged += new System.EventHandler(this.logBox_VisibleChanged);
// //
// lblWarnMsg // lblWarnMsg
// //
......
...@@ -470,5 +470,10 @@ namespace OnlineStore.ACPackingStore ...@@ -470,5 +470,10 @@ namespace OnlineStore.ACPackingStore
FormManager.CloseAxisDebug(); FormManager.CloseAxisDebug();
FormManager.CloseIoStatus(); FormManager.CloseIoStatus();
} }
private void logBox_VisibleChanged(object sender, EventArgs e)
{
LogUtil.UpdateLogbox();
}
} }
} }
...@@ -91,24 +91,11 @@ namespace OnlineStore.Common ...@@ -91,24 +91,11 @@ namespace OnlineStore.Common
} }
} }
private static List<string> logList = new List<string>(); private static List<string> logList = new List<string>();
public static string LastText = "";
private static void ShowLogPro(string msg, Color color) private static void ShowLogPro(string msg, Color color)
{ {
try try
{ {
//if (logList.Count > 0)
//{
// logList.RemoveAt(0);
//}
//if (logList.Count >= showCount)
//{
// logList.RemoveAt(logList.Count - 1);
//}
//System.DateTime now = System.DateTime.Now;
//logList.Insert(0, now.ToLongTimeString() + " " + msg + Environment.NewLine);
//logList.Insert(0, Environment.NewLine);
if (logList.Count > 0) if (logList.Count > 0)
{ {
// logList.RemoveAt(0); // logList.RemoveAt(0);
...@@ -128,23 +115,44 @@ namespace OnlineStore.Common ...@@ -128,23 +115,44 @@ namespace OnlineStore.Common
{ {
return; return;
} }
LastText = text;
if (logBox.Visible)
{
logBox.Text = text; logBox.Text = text;
// logBox.Focus(); //使文本框获取焦点 // logBox.Focus(); //使文本框获取焦点
logBox.AppendText(now.ToLongTimeString() + " " + msg + Environment.NewLine); //增加文本 logBox.AppendText(now.ToLongTimeString() + " " + msg + Environment.NewLine); //增加文本
TimeSpan span = DateTime.Now - lastTime;
if (span.TotalSeconds > 10)
{
lastTime = DateTime.Now;
logBox.Select(logBox.Text.Length, 0); //设置光标的位置到文本尾 logBox.Select(logBox.Text.Length, 0); //设置光标的位置到文本尾
logBox.ScrollToCaret(); //滚动到控件光标处 logBox.ScrollToCaret(); //滚动到控件光标处
} }
}
}
catch (Exception ex) catch (Exception ex)
{ {
LOGGER.Error("出错:" + ex.ToString()); LOGGER.Error("出错:" + ex.ToString());
} }
} }
private static DateTime lastTime = DateTime.Now;
public static void UpdateLogbox()
{
if (logBox != null && logBox.Visible)
{
logBox.Text = LastText;
logBox.Select(logBox.Text.Length, 0); //设置光标的位置到文本尾
logBox.ScrollToCaret(); //滚动到控件光标处
}
}
public static void ClearLog() public static void ClearLog()
{ {
if (logBox != null) if (logBox != null)
{ {
LastText = "";
logList.Clear(); logList.Clear();
logBox.Text = ""; logBox.Text = "";
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!