-
Notifications
You must be signed in to change notification settings - Fork 3
/
errorHandler.cs
60 lines (55 loc) · 2.23 KB
/
errorHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using MySql.Data.MySqlClient;
namespace cs_elbot
{
public class errorHandler
{
private Logger TheLogger = new Logger();
public errorHandler()
{
}
public void errorWriter(Exception oException)
{
TheLogger.Log("Error in " + oException.TargetSite + " due to : " + oException.Message + "\n");
string errorText = oException.ToString();
errorWriter(errorText);
}
public void errorWriter(MySqlException oMySQLException)
{
TheLogger.Log("ExecSql Error in " + oMySQLException.TargetSite + " due to : " + oMySQLException.Message + "\n");
string errorText = oMySQLException.ToString();
errorWriter(errorText);
}
private void errorWriter(string errorText)
{
writeErrorMessage(errorText);
Console.Beep(4400, 50);
}
public void writeErrorMessage(string errorText)
{
MySqlConnection MyConnection = new MySqlConnection("Server=" + MainClass.SqlServer + ";Port=" + MainClass.SqlPort.ToString() + ";Database=" + MainClass.SqlDatabase + ";Uid=" + MainClass.SqlUsername + ";Pwd=" + MainClass.SqlPassword + ";");
MyConnection.Open();
string insertCommand = "INSERT INTO botError (botid, errortext, errordate) VALUES (" + Settings.botid + ",\"" + errorText + "\",SYSDATE())";
MySqlCommand cmd = new MySqlCommand(insertCommand, MyConnection);
try
{
cmd.ExecuteNonQuery();
}
catch (MySqlException oMySQLException)
{
TheLogger.Log("ExecSql Error in " + oMySQLException.TargetSite + " due to : " + oMySQLException.Message + "\n");
TheLogger.Log("ExecSql by SQL : " + insertCommand + "\n");
}
catch (Exception oException)
{
TheLogger.Log("ExecSql Error in " + oException.TargetSite + " due to : " + oException.Message + "\n");
TheLogger.Log("ExecSql by SQL : " + insertCommand + "\n");
}
finally
{
Console.Beep(4400, 50);
}
MyConnection.Close();
}
}
}