GraphQLTest: improve logging

This commit is contained in:
Jonathan Jenne
2024-01-22 10:28:43 +01:00
parent 3e49d66e92
commit 35f675e21a
5 changed files with 105 additions and 25 deletions

View File

@@ -9,9 +9,9 @@ Imports System.Net
Imports System.Text.RegularExpressions
Public Class frmMain
Private WithEvents _Interface As GraphQLInterface
Private _LogConfig As LogConfig
Private _Logger As Logger
Private _Interface As GraphQLInterface
Private _MSSQL As MSSQLServer
Private _Config As ConfigManager(Of Config)
Private _Datapools As New List(Of String) From {
@@ -73,21 +73,36 @@ Public Class frmMain
cmbQuery.SelectedIndex = oIndex
_MSSQL = New MSSQLServer(_LogConfig, _Config.Config.ConnectionString)
LogInfo("Initialization finished")
Catch ex As Exception
_Logger.Error(ex)
LogError(ex)
MsgBox(ex.Message, MsgBoxStyle.Critical, Text)
End Try
End Sub
Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
Try
SaveConfig()
lbLog.Items.Clear()
LogInfo("START OF REQUEST")
LogInfo("Looking up certificate by fingerprint..")
_Interface = New GraphQLInterface(_LogConfig,
txtBaseUrl.Text,
txtUsername.Text,
txtPassword.Text,
txtCertFingerprint.Text)
LogInfo("Certificate Subject: [{0}]", _Interface.Certificate.Subject)
LogInfo("Certificate Issuer: [{0}]", _Interface.Certificate.Issuer)
LogInfo("Certificate Fingerprint: [{0}]", _Interface.Certificate.Thumbprint)
If _Config.Config.HasProxySet() And _Config.Config.HasProxyCredentialsSet() Then
Dim oURI As New Uri($"http://{_Config.Config.ProxyHost}:{_Config.Config.ProxyPort}")
Dim oCredentials As New NetworkCredential(_Config.Config.ProxyUsername, _Config.Config.ProxyPassword)
@@ -108,18 +123,21 @@ Public Class frmMain
_Logger.Debug("Proxy not set.")
End If
LogInfo("Starting login..")
Dim oResponse = _Interface.Login
_Interface.SaveCookies(oResponse.Cookies.Item(0))
If oResponse.StatusCode = Net.HttpStatusCode.OK Then
MsgBox("Login Successful!", MsgBoxStyle.Information, Text)
LogInfo("Login Successful!")
Else
MsgBox("Login failed! Check Certificate and User Credentials!", MsgBoxStyle.Critical, Text)
LogInfo("Login failed! Check Certificate and User Credentials!")
End If
Catch ex As Exception
_Logger.Error(ex)
MsgBox(ex.Message, MsgBoxStyle.Critical, Text)
LogError(ex)
End Try
LogInfo("END OF REQUEST")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
@@ -246,8 +264,8 @@ Public Class frmMain
Private Sub frmMain_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Try
SaveConfig()
Dim oLogoutResponse = _Interface.Logout()
If oLogoutResponse.StatusCode = Net.HttpStatusCode.OK Then
Dim oLogoutResponse = _Interface?.Logout()
If oLogoutResponse?.StatusCode = Net.HttpStatusCode.OK Then
_Logger.Info("Logout successful.")
End If
Catch ex As Exception
@@ -267,4 +285,19 @@ Public Class frmMain
_Config.Config.CurrentQuery = cmbQuery.Text
_Config.Save()
End Sub
Private Sub LogInfo(pMessage As String, ParamArray pParams As String())
Dim oMessage = String.Format(pMessage, pParams)
lbLog.Items.Add(oMessage)
_Logger.Info(oMessage)
End Sub
Private Sub LogError(pException As Exception)
lbLog.Items.Add(pException.Message)
_Logger.Error(pException)
End Sub
Private Sub _Interface_LogRequested(sender As Object, e As String) Handles _Interface.LogRequested
LogInfo(e)
End Sub
End Class