Imports IntraSell_DLL
Imports IntraSell_Net_Base

Public Class Log
    Inherits AbstractForm

    Private Sub Form_Verlassen() Handles MyBase.Verlassen
        Me.Close()
    End Sub

    Private Sub Log_Load(sender As Object, e As System.EventArgs) Handles MyBase.Load
        Try
            LogTextBox.Text = "" 'empty
            ParentBindingNavigator.Visible = False
            Show()
            'say to logger that the window is open and should write here 
            AddHandler IntraSell_DLL.LogEvent, AddressOf LogEvent
            Me.CheckBoxLOG_DEBUG_AKTIV.Checked = ExistsVarValue(Variablen.LOG_DEBUG_AKTIV) AndAlso VarValue(Variablen.LOG_DEBUG_AKTIV)
            WriteLog("Log form started")
        Catch ex As Exception
            HandleAppError(ex, Silent:=True)
        End Try
    End Sub

    Private Sub LogEvent(logLine As String)
        LogTextBox.Invoke(Sub()
                              If LogTextBox.Text.Length > 10000 Then
                                  LogTextBox.Text = Strings.Right(LogTextBox.Text, 10000 - logLine.Length)
                              End If
                              LogTextBox.AppendText(logLine)
                          End Sub)
    End Sub

    Private Sub TimerAutoclose_Tick(sender As Object, e As EventArgs) Handles TimerAutoclose.Tick
        Close()
    End Sub

    Private Sub CheckBoxLOG_DEBUG_AKTIV_Click(sender As Object, e As EventArgs) Handles CheckBoxLOG_DEBUG_AKTIV.Click
        SetVarValue(Variablen.LOG_DEBUG_AKTIV, CheckBoxLOG_DEBUG_AKTIV.Checked)
        If CheckBoxLOG_DEBUG_AKTIV.Checked Then
            System.Environment.SetEnvironmentVariable("LOG_DEBUG_AKTIV", "True")
        Else
            System.Environment.SetEnvironmentVariable("LOG_DEBUG_AKTIV", Nothing)
        End If
        WriteLog("LOG_DEBUG_AKTIV=" & System.Environment.GetEnvironmentVariable("LOG_DEBUG_AKTIV"))
    End Sub
End Class