客户端未知异常将发送到服务器记录,服务器新增客户端异常记录日志

This commit is contained in:
dathlin
2017-06-27 15:08:32 +08:00
parent 8a0fda41e4
commit 350b1f37a2
5 changed files with 98 additions and 2 deletions

View File

@@ -50,6 +50,8 @@ namespace 软件系统客户端模版
this.userButton11 = new HslCommunication.Controls.UserButton();
this.userButton12 = new HslCommunication.Controls.UserButton();
this.userButton13 = new HslCommunication.Controls.UserButton();
this.userButton14 = new HslCommunication.Controls.UserButton();
this.userButton15 = new HslCommunication.Controls.UserButton();
this.SuspendLayout();
//
// textBox1
@@ -349,11 +351,43 @@ namespace 软件系统客户端模版
this.userButton13.UIText = "Udp日志查看";
this.userButton13.Click += new System.EventHandler(this.userButton13_Click);
//
// userButton14
//
this.userButton14.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.userButton14.BackColor = System.Drawing.Color.Transparent;
this.userButton14.CustomerInformation = "";
this.userButton14.EnableColor = System.Drawing.Color.FromArgb(((int)(((byte)(190)))), ((int)(((byte)(190)))), ((int)(((byte)(190)))));
this.userButton14.Font = new System.Drawing.Font("微软雅黑", 9F);
this.userButton14.Location = new System.Drawing.Point(626, 300);
this.userButton14.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.userButton14.Name = "userButton14";
this.userButton14.Size = new System.Drawing.Size(103, 26);
this.userButton14.TabIndex = 25;
this.userButton14.UIText = "客户端日志查看";
this.userButton14.Click += new System.EventHandler(this.userButton14_Click);
//
// userButton15
//
this.userButton15.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.userButton15.BackColor = System.Drawing.Color.Transparent;
this.userButton15.CustomerInformation = "";
this.userButton15.EnableColor = System.Drawing.Color.FromArgb(((int)(((byte)(190)))), ((int)(((byte)(190)))), ((int)(((byte)(190)))));
this.userButton15.Font = new System.Drawing.Font("微软雅黑", 9F);
this.userButton15.Location = new System.Drawing.Point(734, 300);
this.userButton15.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.userButton15.Name = "userButton15";
this.userButton15.Size = new System.Drawing.Size(103, 26);
this.userButton15.TabIndex = 26;
this.userButton15.UIText = "客户端日志清空";
this.userButton15.Click += new System.EventHandler(this.userButton15_Click);
//
// FormLog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(849, 547);
this.Controls.Add(this.userButton15);
this.Controls.Add(this.userButton14);
this.Controls.Add(this.userButton12);
this.Controls.Add(this.userButton13);
this.Controls.Add(this.userButton10);
@@ -407,5 +441,7 @@ namespace 软件系统客户端模版
private UserButton userButton11;
private UserButton userButton12;
private UserButton userButton13;
private UserButton userButton14;
private UserButton userButton15;
}
}

View File

@@ -116,6 +116,17 @@ namespace 软件系统客户端模版
}
private void userButton14_Click(object sender, EventArgs e)
{
ReadFromServer(CommonHeadCode.SimplifyHeadCode.);
}
private void userButton15_Click(object sender, EventArgs e)
{
ClearFromServer(CommonHeadCode.SimplifyHeadCode.);
}
/// <summary>
/// 查询日志的缓存
/// </summary>
@@ -162,6 +173,5 @@ namespace 软件系统客户端模版
textBox1.Text = LogTemp;
}
}
}

View File

@@ -19,7 +19,8 @@ namespace 软件系统客户端模版
[STAThread]
static void Main()
{
//捕获未处理的异常
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
//=====================================================================
//为了强制只启动一个应用程序的实例
@@ -64,6 +65,20 @@ namespace 软件系统客户端模版
}
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
if(e.ExceptionObject is Exception ex)
{
//使用UDP方法传送会服务器
string info = $"{Environment.NewLine}信息:{ex.Message}" +
$"{Environment.NewLine}类型:{ex.GetType().ToString()}" +
$"{Environment.NewLine}堆栈:{ex.StackTrace}" +
$"{Environment.NewLine}方法:{ex.TargetSite.Name}" +
$"{Environment.NewLine}" + "=".PadLeft(50, '=');
UserClient.Net_simplify_client.ReadFromServer(CommonLibrary.CommonHeadCode.SimplifyHeadCode., info);
}
}
[DllImport("User32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);