Namespace Tools
    Public Class CLog

        Private Shared myInstance As CLog
        Private _Dbg As DebugLevel = DebugLevel.ALL
        Private _Trace As Trace

        Public Enum Msg
            INF
            WRN
            ERR
        End Enum

        Public Enum Lev
            Principal = 1
            Secondary = 2
            CyclicPrincipal = 3
            CyclicSecondary = 4
        End Enum

        Public Enum DebugLevel
            OFF = 0
            MAIN = 1
            ALL = 2
        End Enum

        Public Property Dbg() As DebugLevel
            Get
                Return _Dbg
            End Get
            Set(ByVal value As DebugLevel)
                _Dbg = value
            End Set
        End Property

        Public Shared Function GetInstance() As CLog
            If myInstance Is Nothing Then
                myInstance = New CLog()
            End If
            Return myInstance
        End Function

        Public Sub W(ByVal Lev As Msg, ByVal Message As String, Optional ByVal Desc As String = "")
            Dim szMessage As String

            szMessage = Message
            If Desc <> "" Then szMessage &= " (" & Desc & ")"

            Trace.WriteLine(szMessage)
        End Sub

        Public Sub WI(ByVal Message As String, Optional ByVal Desc As String = "", Optional ByVal Level As Lev = Lev.Principal, Optional ByVal MsgBox As Boolean = False)
            If Me.Dbg >= Level Then
                W(Msg.INF, Message, Desc)
            End If
            'If MsgBox Then ShowMessageBox(Message, Desc, Msg.INF)
        End Sub
        Public Sub WW(ByVal Message As String, Optional ByVal Desc As String = "", Optional ByVal MsgBox As Boolean = False)
            If Me.Dbg >= Lev.Principal Then
                W(Msg.WRN, Message, Desc)
            End If
            'If MsgBox Then ShowMessageBox(Message, Desc, Msg.WRN)
        End Sub
        Public Sub WE(ByVal Message As String, Optional ByVal Desc As String = "", Optional ByVal MsgBox As Boolean = False)
            W(Msg.ERR, Message, Desc)
            'If MsgBox Then ShowMessageBox(Message, Desc, Msg.ERR)
        End Sub

        'Private Shared Sub ShowMessageBox(ByVal Message As String, Optional ByVal Desc As String = "", Optional ByVal MsgClass As Msg = Msg.INF)
        '    Select Case MsgClass
        '        Case Msg.INF
        '            MessageBox.Show(Message & vbNewLine & Desc, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Information)
        '        Case Msg.WRN
        '            MessageBox.Show(Message & vbNewLine & Desc, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Warning)
        '        Case Msg.ERR
        '            MessageBox.Show(Message & vbNewLine & Desc, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
        '            End 'In caso di errore critico con msgbox esco dall'applicazione
        '    End Select
        'End Sub

    End Class
End Namespace
