Repository navigation
Expand file tree
/
Copy pathLogError.cs
More file actions
73 lines (67 loc) · 2.37 KB
/
Copy pathLogError.cs
File metadata and controls
73 lines (67 loc) · 2.37 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
using DataHelpers;
using BusinessObjects;
using System.Windows.Forms;
namespace AppWrapper
{
public class LogError
{
const string eol = "\r\n";
public LogError(Exception ex, bool showMsgBox, string moduleAndMethod)
{
try
{
string msg = $"Error Message from {moduleAndMethod}: " +
ex.Message + eol +
"Error Type: " + ex.GetType().ToString() + eol +
"Error Details: " + eol + ex.ToString();
if (showMsgBox)
MessageBox.Show(msg, "Program Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
try
{
StackTrace st = new StackTrace(true);
msg += "Stack Trace: " + eol + st.ToString();
}
catch (Exception)
{
}
WriteErrorLogToDB(new StringBuilder(msg), moduleAndMethod);
}
catch (Exception ex2)
{
}
}
public LogError(string err, bool showMsgBox, string moduleAndMethod)
{
string msg = $"Error Message from {moduleAndMethod}: " + err + eol;
if (showMsgBox)
MessageBox.Show(msg, "Program Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
WriteErrorLogToDB(new StringBuilder(msg), moduleAndMethod);
}
private Tuple<string, string> SplitModuleFromMethod(string moduleAndMethod)
{
string[] s = moduleAndMethod.Split('.');
return Tuple.Create(s[0], s.Length > 1 ? s[1] : string.Empty);
}
private void WriteErrorLogToDB(StringBuilder sb, string moduleAndMethod)
{
Tuple<string, string> mm = SplitModuleFromMethod(moduleAndMethod);
var hlpr = new DHMisc();
_ = hlpr.WriteErrorLog(new ErrorLog
{
Module = mm.Item1,
Method = mm.Item2,
Message = sb.ToString(),
DateCreated = DateTime.Now,
Machine = Environment.MachineName,
Username = Environment.UserName
});
}
}
}