1 |
#Region "Microsoft.VisualBasic::114172961e80001497cd83b56e46bcad, Microsoft.VisualBasic.Core\ApplicationServices\Debugger\Logging\LogFile\LogFile.vb"
|
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 |
#End Region
|
49 |
|
50 |
Imports System.IO
|
51 |
Imports System.Runtime.CompilerServices
|
52 |
Imports System.Text
|
53 |
Imports Microsoft.VisualBasic.ComponentModel
|
54 |
Imports Microsoft.VisualBasic.Parallel
|
55 |
Imports Microsoft.VisualBasic.Terminal.STDIO__
|
56 |
|
57 |
Namespace ApplicationServices.Debugging.Logging
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
Public Class LogFile : Inherits ITextFile
|
67 |
Implements ISaveHandle
|
68 |
Implements IDisposable
|
69 |
Implements I_ConsoleDeviceHandle
|
70 |
|
71 |
Dim buffer As TextWriter
|
72 |
Dim counts&
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
Public ReadOnly Property FileName As String
|
81 |
Get
|
82 |
Return MyBase.FilePath.BaseName
|
83 |
End Get
|
84 |
End Property
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
Public Shared ReadOnly Property NowTimeNormalizedString As String
|
93 |
Get
|
94 |
Return $"{Format(Now.Month, "00")}{ Format(Now.Day, "00")}{Format(Now.Hour, "00")}{Format(Now.Minute, "00")}{Format(Now.Second, "00")}"
|
95 |
End Get
|
96 |
End Property
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
Public Sub New(Path As String, Optional AutoFlush As Boolean = True, Optional bufferSize As Integer = 1024)
|
105 |
Dim file As New FileStream(Path, FileMode.Append)
|
106 |
|
107 |
buffer = New StreamWriter(file, Encoding.UTF8, bufferSize) With {
|
108 |
.AutoFlush = AutoFlush
|
109 |
}
|
110 |
buffer.WriteLine($"//{vbTab}[{Now.ToString}]{vbTab}{New String("=", 25)} START WRITE LOGGING SECTION {New String("=", 25)}" & vbCrLf)
|
111 |
FilePath = FileIO.FileSystem.GetFileInfo(Path).FullName
|
112 |
End Sub
|
113 |
|
114 |
Public Sub LogException(Msg As String, <CallerMemberName> Optional Object$ = Nothing)
|
115 |
Call WriteLine(Msg, [Object], Type:=MSG_TYPES.ERR)
|
116 |
End Sub
|
117 |
|
118 |
Public Sub LogException(ex As Exception)
|
119 |
Call WriteLine(ex.ToString, "", Type:=MSG_TYPES.ERR)
|
120 |
End Sub
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
Public Sub WriteLine(Msg As String, [Object] As String, Optional Type As MSG_TYPES = MSG_TYPES.INF)
|
129 |
Dim LogEntry As New LogEntry With {
|
130 |
.Msg = Msg,
|
131 |
.Object = [Object],
|
132 |
.Time = Now,
|
133 |
.Type = Type
|
134 |
}
|
135 |
|
136 |
buffer.WriteLine(LogEntry.ToString)
|
137 |
counts += 1
|
138 |
End Sub
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
Private Function SaveLog() As Boolean
|
145 |
Call buffer.WriteLine(vbCrLf & $"//{vbTab}{New String("=", 25)} END OF LOG FILE {New String("=", 25)}")
|
146 |
Call buffer.WriteLine(vbCrLf)
|
147 |
Call buffer.Flush()
|
148 |
|
149 |
Return True
|
150 |
End Function
|
151 |
|
152 |
Public Overrides Function ToString() As String
|
153 |
Return $"[{counts} records]'{FilePath.ToFileURL}'"
|
154 |
End Function
|
155 |
|
156 |
Public Function ReadLine() As String Implements I_ConsoleDeviceHandle.ReadLine
|
157 |
Return ""
|
158 |
End Function
|
159 |
|
160 |
Public Sub WriteLine(Optional s As String = "") Implements I_ConsoleDeviceHandle.WriteLine
|
161 |
Call WriteLine(s, Type:=MSG_TYPES.INF, [Object]:="")
|
162 |
End Sub
|
163 |
|
164 |
Public Sub WriteLine(s As String())
|
165 |
Dim str As String = String.Join(vbCrLf, s)
|
166 |
Call WriteLine(str, Type:=MSG_TYPES.INF, [Object]:="")
|
167 |
End Sub
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
Public Sub WriteLine(s As String, ParamArray args() As String) Implements I_ConsoleDeviceHandle.WriteLine
|
176 |
Dim [Object] As String = IIf(String.IsNullOrEmpty(args(0)), "", args(0))
|
177 |
Call WriteLine(s, Type:=MSG_TYPES.INF, [Object]:=[Object])
|
178 |
End Sub
|
179 |
|
180 |
Public Overloads Function Read() As Integer Implements I_ConsoleDeviceHandle.Read
|
181 |
Return -1
|
182 |
End Function
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
Public Overrides Function Save(Optional FilePath As String = "", Optional Encoding As Encoding = Nothing) As Boolean
|
192 |
FilePath = getPath(FilePath)
|
193 |
Return SaveLog()
|
194 |
End Function
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
Public Shared Function SystemInfo() As String
|
201 |
Dim sBuilder As New StringBuilder(1024)
|
202 |
|
203 |
Call sBuilder.AppendLine($"{NameOf(OSVersionInfo.BuildVersion)}:={OSVersionInfo.BuildVersion}")
|
204 |
Call sBuilder.AppendLine($"{NameOf(OSVersionInfo.Edition)}:={OSVersionInfo.Edition}")
|
205 |
Call sBuilder.AppendLine($"{NameOf(OSVersionInfo.MajorVersion)}:={OSVersionInfo.MajorVersion}")
|
206 |
Call sBuilder.AppendLine($"{NameOf(OSVersionInfo.MinorVersion)}:={OSVersionInfo.MinorVersion}")
|
207 |
Call sBuilder.AppendLine($"{NameOf(OSVersionInfo.WindowsName)}:={OSVersionInfo.WindowsName}")
|
208 |
Call sBuilder.AppendLine($"{NameOf(OSVersionInfo.OSBits)}:={OSVersionInfo.OSBits}")
|
209 |
Call sBuilder.AppendLine($"{NameOf(OSVersionInfo.ProcessorBits)}:={OSVersionInfo.ProcessorBits}")
|
210 |
Call sBuilder.AppendLine($"{NameOf(OSVersionInfo.ProgramBits)}:={OSVersionInfo.ProgramBits}")
|
211 |
Call sBuilder.AppendLine($"{NameOf(OSVersionInfo.RevisionVersion)}:={OSVersionInfo.RevisionVersion}")
|
212 |
Call sBuilder.AppendLine($"{NameOf(OSVersionInfo.ServicePack)}:={OSVersionInfo.ServicePack}")
|
213 |
Call sBuilder.AppendLine($"{NameOf(OSVersionInfo.Version)}:={OSVersionInfo.Version.ToString}")
|
214 |
|
215 |
Return sBuilder.ToString
|
216 |
End Function
|
217 |
|
218 |
Protected Overrides Function __getDefaultPath() As String
|
219 |
Return FilePath
|
220 |
End Function
|
221 |
|
222 |
Protected Overrides Sub Dispose(disposing As Boolean)
|
223 |
Call SaveLog()
|
224 |
MyBase.Dispose(disposing)
|
225 |
End Sub
|
226 |
End Class
|
227 |
End Namespace
|