Begin implementation of logger in the software
This commit is contained in:
parent
e7e1813d53
commit
b170a860be
@ -5,12 +5,12 @@ Public Class Logger
|
|||||||
|
|
||||||
Dim logFileName As String = "logs\" & DateTime.Now.ToString("yyyy-MM-dd") & ".txt"
|
Dim logFileName As String = "logs\" & DateTime.Now.ToString("yyyy-MM-dd") & ".txt"
|
||||||
|
|
||||||
Shared Sub Load()
|
Public Sub Load()
|
||||||
If Not My.Computer.FileSystem.DirectoryExists("logs") Then My.Computer.FileSystem.CreateDirectory("logs")
|
If Not My.Computer.FileSystem.DirectoryExists("logs") Then My.Computer.FileSystem.CreateDirectory("logs")
|
||||||
If Not My.Computer.FileSystem.FileExists(logFileName) Then File.WriteAllLines(logFileName, {"LOG FILE - " & DateTime.Now.ToString("dd/MM/yyyy"), "--------------------", "[INFO] Loading software"})
|
If Not My.Computer.FileSystem.FileExists(logFileName) Then File.WriteAllLines(logFileName, {"LOG FILE - " & DateTime.Now.ToString("dd/MM/yyyy"), "--------------------", "[INFO] Loading software"})
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Sub Info(str As String)
|
Public Sub Info(str As String)
|
||||||
Dim objWriter As New StreamWriter(logFileName, True)
|
Dim objWriter As New StreamWriter(logFileName, True)
|
||||||
Try
|
Try
|
||||||
objWriter.WriteLineAsync("[INFO] " & str)
|
objWriter.WriteLineAsync("[INFO] " & str)
|
||||||
@ -20,7 +20,7 @@ Public Class Logger
|
|||||||
objWriter.Close()
|
objWriter.Close()
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Sub Warn(str As String)
|
Public Sub Warn(str As String)
|
||||||
Dim objWriter As New StreamWriter(logFileName, True)
|
Dim objWriter As New StreamWriter(logFileName, True)
|
||||||
Try
|
Try
|
||||||
objWriter.WriteLineAsync("[WARN] " & str)
|
objWriter.WriteLineAsync("[WARN] " & str)
|
||||||
@ -30,7 +30,7 @@ Public Class Logger
|
|||||||
objWriter.Close()
|
objWriter.Close()
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Sub Critical(str As String)
|
Public Sub Critical(str As String)
|
||||||
Dim objWriter As New StreamWriter(logFileName, True)
|
Dim objWriter As New StreamWriter(logFileName, True)
|
||||||
Try
|
Try
|
||||||
objWriter.WriteLineAsync("[CRITICAL] " & str)
|
objWriter.WriteLineAsync("[CRITICAL] " & str)
|
||||||
|
@ -4,9 +4,10 @@ Imports System.Text
|
|||||||
Public Class Main
|
Public Class Main
|
||||||
Dim manualID_selected As Boolean = False
|
Dim manualID_selected As Boolean = False
|
||||||
Dim idList As New ArrayList
|
Dim idList As New ArrayList
|
||||||
|
Dim log As New Logger
|
||||||
|
|
||||||
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
||||||
Logger.Load()
|
log.Load()
|
||||||
CheckIfFirstRun()
|
CheckIfFirstRun()
|
||||||
ListAllInv()
|
ListAllInv()
|
||||||
End Sub
|
End Sub
|
||||||
@ -15,8 +16,9 @@ Public Class Main
|
|||||||
''' Function to check if app is running for the first time
|
''' Function to check if app is running for the first time
|
||||||
''' </summary>
|
''' </summary>
|
||||||
Private Sub CheckIfFirstRun()
|
Private Sub CheckIfFirstRun()
|
||||||
|
log.Info("Check and load of database")
|
||||||
If Not My.Computer.FileSystem.FileExists("db.sqlite") Then
|
If Not My.Computer.FileSystem.FileExists("db.sqlite") Then
|
||||||
If MsgBox("La base de données SQLite est introuvable ou inaccesible, souhaitez-vous la régénérer ?", 4161, "Base SQLite absente ou inacessible") = 1 Then
|
If MsgBox("La base de données SQLite est introuvable ou inaccessible, souhaitez-vous la régénérer ?", 4161, "Base SQLite absente ou inaccessible") = 1 Then
|
||||||
RegenerateDB()
|
RegenerateDB()
|
||||||
Else
|
Else
|
||||||
End
|
End
|
||||||
@ -107,6 +109,7 @@ Public Class Main
|
|||||||
''' Construct the basic structure of SQLite DB
|
''' Construct the basic structure of SQLite DB
|
||||||
''' </summary>
|
''' </summary>
|
||||||
Private Sub RegenerateDB()
|
Private Sub RegenerateDB()
|
||||||
|
log.Warn("Reconstruct database...")
|
||||||
Dim genesis_seq As String = "
|
Dim genesis_seq As String = "
|
||||||
CREATE TABLE `computers_desc` (
|
CREATE TABLE `computers_desc` (
|
||||||
`id` TEXT NOT NULL DEFAULT 0000000000 UNIQUE,
|
`id` TEXT NOT NULL DEFAULT 0000000000 UNIQUE,
|
||||||
|
Reference in New Issue
Block a user