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

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

@@ -53,6 +53,7 @@ namespace CommonLibrary
public static int { get; } = 10010;
public static int { get; } = 10011;
public static int { get; } = 10012;
public static int { get; } = 10013;
@@ -79,6 +80,8 @@ namespace CommonLibrary
public static int { get; } = 11011;
public static int UDP日志查看 { get; } = 11012;
public static int UDP日志清空 { get; } = 11013;
public static int { get; } = 11014;
public static int { get; } = 11015;
/**************************************************************************************
*

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);

View File

@@ -87,6 +87,11 @@ namespace 软件系统服务端模版
{
LogSaveFileName = LogSavePath + @"\advice_log.txt",
};
//初始化客户端异常日志工具
ClientsLogHelper = new SoftLogHelper()
{
LogSaveFileName = LogSavePath + @"\clients_log.txt",
};
//保存路径初始化
UserServer.ServerSettings.FileSavePath = Application.StartupPath + @"\settings.txt";
//加载参数
@@ -467,6 +472,13 @@ namespace 软件系统服务端模版
net_socket_server.SendAllClients(CommonHeadCode.MultiNetHeadCode., data);
net_simplify_server.SendMessage(state, customer, "成功");
}
else if (customer == CommonHeadCode.SimplifyHeadCode.)
{
ClientsLogHelper.SaveError(data);
net_simplify_server.SendMessage(state, customer, "成功");
//如果需要发送您自己的邮件,请取消下面的注释并替代您的邮箱地址
//SoftMail.MailSystem163.SendMail("hsl200909@163.com", "异常记录", "时间:" + DateTime.Now.ToString("O") + Environment.NewLine + data);
}
else
{
net_simplify_server.SendMessage(state, customer, data);
@@ -558,6 +570,17 @@ namespace 软件系统服务端模版
net_simplify_server.SendMessage(state, customer, "成功");
RuntimeLogHelper.SaveWarnning("UDP日志清空");
}
else if (customer == CommonHeadCode.SimplifyHeadCode.)
{
net_simplify_server.SendMessage(state, 0, ClientsLogHelper.GetLogText());
RuntimeLogHelper.SaveInformation("客户端日志查看");
}
else if (customer == CommonHeadCode.SimplifyHeadCode.)
{
ClientsLogHelper.ClearLogText();
net_simplify_server.SendMessage(state, customer, "成功");
RuntimeLogHelper.SaveWarnning("客户端日志清空");
}
else
{
net_simplify_server.SendMessage(state, customer, data);
@@ -1016,6 +1039,8 @@ namespace 软件系统服务端模版
#endregion
#region
/*********************************************************************************************************
*
@@ -1031,5 +1056,12 @@ namespace 软件系统服务端模版
/// 用来记录一般的事物日志
/// </summary>
private SoftLogHelper RuntimeLogHelper { get; set; }
/// <summary>
/// 用来记录客户端的异常日志
/// </summary>
private SoftLogHelper ClientsLogHelper { get; set; }
#endregion
}
}