-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogFileClass.vb
119 lines (111 loc) · 3.42 KB
/
LogFileClass.vb
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
Public Class LogFileClass
Private p_logfilename As String = ""
Public Property LogFileName As String
Get
If p_logfilename <> "" Then
Return p_logfilename
Else
p_logfilename = IO.Path.ChangeExtension(Application.ExecutablePath, ".log")
Return p_logfilename
End If
End Get
Set(value As String)
p_logfilename = value
End Set
End Property
Private Function LogFileExists() As Boolean
If LogFileName <> "" Then
If IO.File.Exists(LogFileName) Then
Return True
Else
Return False
End If
Else
Return False
End If
Return True
End Function
Public Function CreateLogFile() As Boolean
If LogFileName <> "" Then
Try
Dim sw As IO.StreamWriter
sw = IO.File.CreateText(LogFileName)
sw.WriteLine(" Run Greaseweazle Log File")
sw.WriteLine("-============================-")
sw.WriteLine("")
sw.WriteLine("Create on " + DateTime.Today.ToString("yyyy-MM-dd") + " at " + DateTime.Now.ToString("HH:mm:ss"))
sw.WriteLine("")
sw.Flush()
sw.Close()
Return True
Catch ex As Exception
Return False
End Try
Else
Return False
End If
Return True
End Function
Private Function AppendToLog(ByVal StringToWrite As String) As Boolean
Try
Dim sw As IO.StreamWriter
sw = IO.File.AppendText(LogFileName)
sw.WriteLine(StringToWrite)
sw.Flush()
sw.Close()
Return True
Catch ex As Exception
Return False
End Try
End Function
Public Function WriteToLog(ByVal StringToWrite As String) As Boolean
If LogFileName <> "" Then
If LogFileExists() = True Then
If AppendToLog(StringToWrite) = True Then
Return True
Else
Return False
End If
Else
If CreateLogFile() = True Then
AppendToLog(StringToWrite)
Return True
Else
Return False
End If
End If
Else
Return False
End If
Return True
End Function
Private Function AppendToLog(ByVal StringsToWrite As String()) As Boolean
Try
IO.File.AppendAllLines(LogFileName, StringsToWrite)
Return True
Catch ex As Exception
Return False
End Try
End Function
Public Function WriteToLog(ByVal StringsToWrite As String()) As Boolean
If LogFileName <> "" Then
If LogFileExists() = True Then
If AppendToLog(StringsToWrite) = True Then
Return True
Else
Return False
End If
Else
If CreateLogFile() = True Then
AppendToLog(StringsToWrite)
Return True
Else
Return False
End If
End If
Else
Return False
End If
Return True
End Function
End Class