-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBootstrapLog.cs
150 lines (131 loc) · 4.7 KB
/
BootstrapLog.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using Gurock.SmartInspect;
using System;
using System.Drawing;
using System.IO;
namespace SmartLogger
{
public sealed class Bootstrap
{
private static bool clearLog;
private static bool details;
private static bool appendLog;
private static SmartInspect smartInspect = null;
private static Session session = null;
private static readonly object padlock = new object();
public bool AppendLog
{
get => appendLog;
set => appendLog = value;
}
public bool Details
{
get => details;
set => details = value;
}
public bool ClearLog
{
get => clearLog;
set => clearLog = value;
}
private static string BootstrapLogFilename()
{
string folderName = "StartupLogs"; // The custom folder name
string appBasePath = AppDomain.CurrentDomain.BaseDirectory; // Get the application base directory
string folderPath = Path.Combine(appBasePath, folderName); // Combine the base path with the folder name to get the full path
// Ensure the folder exists
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
// Create a timestamped filename
string timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
string fileName = $"StartupIssues_{timestamp}.txt";
string filePath = Path.Combine(folderPath, fileName);
return filePath;
// return $"{System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName)}\\StartupIssues.txt";
}
private static void GetCommandLineArguments()
{
appendLog = false;
details = true; // default to true for initial testing
clearLog = false;
string[] arguments = Environment.GetCommandLineArgs();
foreach (string item in arguments)
{
if (item.ToLower().Equals("-bs.append"))
{
appendLog = true;
}
else if (item.ToLower().Equals("-bs.detail"))
{
details = true;
}
else if (item.ToLower().Equals("-bs.clear"))
{
clearLog = true;
}
}
}
private static void DebugCommandLineArguments()
{
string[] arguments = Environment.GetCommandLineArgs();
foreach (string item in arguments)
{
session.LogDebug(item);
}
session.LogBool("Clear", clearLog);
session.LogBool("Append", appendLog);
session.LogBool("Detail", details);
session.LogDebug($"SmartInspect version: {SmartInspect.Version}");
}
public static void Init()
{
lock (padlock)
{
if (session == null)
{
GetCommandLineArguments();
smartInspect = new SmartInspect(Configuration.PlainAppFilename() + ".BootStrap");
smartInspect.Connections = $"text(append=\"{appendLog}\", filename=\"{BootstrapLogFilename()}\"), tcp(host=\"72.234.252.135\", reconnect=\"true\", reconnect.interval=\"60\")";
smartInspect.Enabled = true;
session = smartInspect.AddSession("StartupIssues");
session.Color = Color.Tomato;
if (details )
{
session.Level = Gurock.SmartInspect.Level.Debug;
}
else
{
session.Level = Gurock.SmartInspect.Level.Warning;
}
session.Active = true;
if (appendLog)
{
session.LogSeparator(Gurock.SmartInspect.Level.Warning);
session.LogWarning($"Executable Starting: Using SmartInspect version: {SmartInspect.Version}");
}
if (clearLog)
{
session.ClearAll();
}
if (details)
{
DebugCommandLineArguments();
}
}
}
}
public static Session Log
{
get
{
lock (padlock)
{
Init();
return session;
}
}
}
}
}