-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogFile.cs
82 lines (75 loc) · 3.43 KB
/
LogFile.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.IO;
namespace Aiche_Bois
{
static class LogFile
{
/// <summary>
/// log file method
/// </summary>
/// <param name="ex"></param>
static public void Message(Exception ex)
{
String targetPath = Program.generale_path + "\\journal_des_erreurs";
if (!Directory.Exists(targetPath))
{
Directory.CreateDirectory(targetPath);
}
string message = string.Format("Time: {0}", DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt"));
message += "<br>";
message += "-----------------------------------------------------------";
message += "<br>";
message += "<pre>" + string.Format("Message: {0}", ex.Message);
message += "<br>";
message += "<pre>" + string.Format("StackTrace: {0}", ex.StackTrace);
message += "<br>";
message += "<pre>" + string.Format("Source: {0}", ex.Source);
message += "<br>";
message += "<pre>" + string.Format("TargetSite: {0}", ex.TargetSite.ToString());
message += "<br>";
message += "-----------------------------------------------------------";
message += "<br>";
String format = @"
<!DOCTYPE html>
<html>
<head>
<title>Log File Error</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Ubuntu&display=swap');
*
{
box-sizing: border-box;
margin: 0;
padding: 0;
}
body
{
width: 90%;
margin: auto;
background-color: #1f1f1f;
color: #efefef;
font-family: 'Ubuntu', sans-serif;
}
div
{
font-family: 'Ubuntu', sans-serif;
padding: 10px;
font-size: meduim;
margin: auto;
}
</style>
</head>
<body>
<div>
" + message + @"
</div>
</body>
</html>";
using (StreamWriter writer = new StreamWriter(targetPath + "\\ErrorLog.html", true))
{
writer.WriteLine(format);
writer.Close();
}
}
}
}