forked from sergiisyrovatchenko/SQLIndexManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOutput.cs
More file actions
74 lines (57 loc) · 1.71 KB
/
Copy pathOutput.cs
File metadata and controls
74 lines (57 loc) · 1.71 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
74
using System;
using System.IO;
using DevExpress.XtraBars;
namespace SQLIndexManager {
public class OutputEvent {
public DateTime DateTime { get; set; }
public string Message { get; set; }
public DateTime? Duration { get; set; }
}
public class Output {
private static Output _log;
private BarStaticItem _control;
public static Output Current => _log ?? (_log = new Output());
private Output() {
if (File.Exists(AppInfo.LogFileName)) {
try {
File.Delete(AppInfo.LogFileName);
}
catch { }
}
}
public void SetOutputControl(BarStaticItem control) {
_control = control;
}
public void AddCaption(string message) {
try {
_control.Caption = message;
}
catch { }
}
public void Add(string message, string message2 = null, long? elapsedMilliseconds = null) {
DateTime now = DateTime.Now;
DateTime? duration = null;
string msg = message;
if (elapsedMilliseconds >= 0) {
duration = (new DateTime(0)).AddMilliseconds((double) elapsedMilliseconds);
msg = $"Elapsed time: {duration:HH:mm:ss:fff}. {message}";
}
OutputEvent ev = new OutputEvent {
DateTime = now,
Message = string.IsNullOrEmpty(message2) ? message : $"{message}{Environment.NewLine}{message2}",
Duration = duration
};
try {
if (_control != null) {
_control.Caption = msg;
}
using (StreamWriter sw = File.AppendText(AppInfo.LogFileName)) {
sw.WriteLine($"{now:HH:mm:ss.fff} - {msg}");
if (!string.IsNullOrEmpty(message2))
sw.WriteLine(message2);
}
}
catch { }
}
}
}