Commit 6a47659d LN

日志修改

1 个父辈 4e115a0a
...@@ -701,12 +701,13 @@ ...@@ -701,12 +701,13 @@
this.richTextBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.richTextBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.richTextBox1.Font = new System.Drawing.Font("微软雅黑", 7.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.richTextBox1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.richTextBox1.Location = new System.Drawing.Point(7, 92); this.richTextBox1.Location = new System.Drawing.Point(7, 92);
this.richTextBox1.Name = "richTextBox1"; this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(545, 425); this.richTextBox1.Size = new System.Drawing.Size(545, 454);
this.richTextBox1.TabIndex = 256; this.richTextBox1.TabIndex = 256;
this.richTextBox1.Text = ""; this.richTextBox1.Text = "";
this.richTextBox1.VisibleChanged += new System.EventHandler(this.richTextBox1_VisibleChanged);
// //
// groupBox1 // groupBox1
// //
...@@ -1670,7 +1671,7 @@ ...@@ -1670,7 +1671,7 @@
this.btnClearLog.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.btnClearLog.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnClearLog.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.btnClearLog.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnClearLog.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btnClearLog.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnClearLog.Location = new System.Drawing.Point(310, 532); this.btnClearLog.Location = new System.Drawing.Point(310, 563);
this.btnClearLog.Name = "btnClearLog"; this.btnClearLog.Name = "btnClearLog";
this.btnClearLog.Size = new System.Drawing.Size(105, 38); this.btnClearLog.Size = new System.Drawing.Size(105, 38);
this.btnClearLog.TabIndex = 224; this.btnClearLog.TabIndex = 224;
...@@ -1853,7 +1854,7 @@ ...@@ -1853,7 +1854,7 @@
this.btnCloseDoor.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.btnCloseDoor.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnCloseDoor.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.btnCloseDoor.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnCloseDoor.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btnCloseDoor.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnCloseDoor.Location = new System.Drawing.Point(146, 532); this.btnCloseDoor.Location = new System.Drawing.Point(146, 563);
this.btnCloseDoor.Name = "btnCloseDoor"; this.btnCloseDoor.Name = "btnCloseDoor";
this.btnCloseDoor.Size = new System.Drawing.Size(105, 38); this.btnCloseDoor.Size = new System.Drawing.Size(105, 38);
this.btnCloseDoor.TabIndex = 258; this.btnCloseDoor.TabIndex = 258;
...@@ -1866,7 +1867,7 @@ ...@@ -1866,7 +1867,7 @@
this.btnOpenDoor.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.btnOpenDoor.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnOpenDoor.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.btnOpenDoor.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnOpenDoor.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btnOpenDoor.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnOpenDoor.Location = new System.Drawing.Point(29, 532); this.btnOpenDoor.Location = new System.Drawing.Point(29, 563);
this.btnOpenDoor.Name = "btnOpenDoor"; this.btnOpenDoor.Name = "btnOpenDoor";
this.btnOpenDoor.Size = new System.Drawing.Size(105, 38); this.btnOpenDoor.Size = new System.Drawing.Size(105, 38);
this.btnOpenDoor.TabIndex = 257; this.btnOpenDoor.TabIndex = 257;
......
...@@ -1386,6 +1386,9 @@ namespace OnlineStore.ACSingleStore ...@@ -1386,6 +1386,9 @@ namespace OnlineStore.ACSingleStore
LogUtil.logBox = this.richTextBox1; LogUtil.logBox = this.richTextBox1;
} }
private void richTextBox1_VisibleChanged(object sender, EventArgs e)
{
LogUtil.UpdateLogbox();
}
} }
} }
...@@ -20,7 +20,7 @@ namespace OnlineStore.Common ...@@ -20,7 +20,7 @@ namespace OnlineStore.Common
public static System.Windows.Forms.RichTextBox logBox = null; public static System.Windows.Forms.RichTextBox logBox = null;
public static int showCount = 30; public static int showCount = 15;
public static bool debug_opened = false; public static bool debug_opened = false;
...@@ -33,31 +33,21 @@ namespace OnlineStore.Common ...@@ -33,31 +33,21 @@ namespace OnlineStore.Common
} }
log.Info(log.Logger.Name + " - " + msg); log.Info(log.Logger.Name + " - " + msg);
if (logBox == null)
{
return;
}
AddToBox(msg, Color.Black); AddToBox(msg, Color.Black);
//clear(); //clear();
} }
public static void info(ILog log,string msg, Color color) public static void info(ILog log,string msg, Color color)
{ {
log.Info(log.Logger.Name + " - " + msg); log.Info(log.Logger.Name + " - " + msg);
if (logBox == null)
{
return;
}
AddToBox(msg, color); AddToBox(msg, color);
} }
public static void debug(ILog log, string msg, Color color) public static void debug(ILog log, string msg, Color color)
{ {
log.Debug(log.Logger.Name + " - " + msg); log.Debug(log.Logger.Name + " - " + msg);
if (debug_opened) if (debug_opened)
{ {
if (logBox == null)
{
return;
}
AddToBox(msg, color); AddToBox(msg, color);
} }
} }
...@@ -65,11 +55,7 @@ namespace OnlineStore.Common ...@@ -65,11 +55,7 @@ namespace OnlineStore.Common
{ {
log.Debug(log.Logger.Name + " - " + msg); log.Debug(log.Logger.Name + " - " + msg);
if (debug_opened) if (debug_opened)
{ {
if (logBox == null)
{
return;
}
AddToBox(msg, Color.Gray); AddToBox(msg, Color.Gray);
} }
} }
...@@ -107,20 +93,8 @@ namespace OnlineStore.Common ...@@ -107,20 +93,8 @@ namespace OnlineStore.Common
} }
public static void error(ILog log, string errorMsg) public static void error(ILog log, string errorMsg)
{ {
//if (!lasErrorLogList.Contains(errorMsg)) log.Error(log.Logger.Name + " - " + errorMsg);
{ AddToBox(errorMsg, Color.Red);
log.Error(log.Logger.Name + " - " + errorMsg);
if (logBox == null)
{
return;
}
AddToBox(errorMsg, Color.Red);
}
//lasErrorLogList.Add(errorMsg);
//if (lasErrorLogList.Count > errCount)
//{
// lasErrorLogList.RemoveAt(0);
//}
} }
private static void AddToBox(string msg, Color color) private static void AddToBox(string msg, Color color)
{ {
...@@ -133,45 +107,84 @@ namespace OnlineStore.Common ...@@ -133,45 +107,84 @@ namespace OnlineStore.Common
LOGGER.Error("出错:" + ex.StackTrace); LOGGER.Error("出错:" + ex.StackTrace);
} }
} }
private static int count = 0; 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
{ {
//clear(); if (logList.Count > 0)
if (count > showCount) {
// logList.RemoveAt(0);
}
if (logList.Count >= showCount)
{ {
count = 0; logList.RemoveAt(0);
logBox.Clear(); }
string text = "";
foreach (string str in logList)
{
text += str;
} }
//logBox.SelectionColor = color;
System.DateTime now = System.DateTime.Now; System.DateTime now = System.DateTime.Now;
logBox.AppendText(now.ToLongTimeString() + " " + msg + Environment.NewLine); logList.Add(now.ToLongTimeString() + " " + msg + Environment.NewLine);
count++; if (logBox == null)
{
return;
}
LastText = text;
if (logBox.Visible)
{
logBox.Text = text;
// logBox.Focus(); //使文本框获取焦点
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.ScrollToCaret(); //滚动到控件光标处
}
}
} }
catch (Exception ex) catch (Exception ex)
{ {
LOGGER.Error("出错:" + ex.ToString()); LOGGER.Error("出错:" + ex.ToString());
} }
} }
public static void debug(string msg) private static DateTime lastTime = DateTime.Now;
{ public static void UpdateLogbox()
debug(LOGGER, msg);
}
public static void error(string errorMsg)
{ {
error( LOGGER,errorMsg); 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();
logBox.Text = ""; logBox.Text = "";
count = 0;
} }
} }
public static void debug(string msg)
{
debug(LOGGER, msg);
}
public static void error(string errorMsg)
{
error( LOGGER,errorMsg);
}
public static void info(string msg) public static void info(string msg)
{ {
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!