Verbesserung der Protokollierung und Konfigurationsbereinigung

Die Änderungen umfassen:

- Anpassung der `App.config`: Entfernen veralteter Einstellungen (`FB_DATABASE`, `FB_USER`, etc.) und Hinzufügen neuer Platzhalter (`Test`).
- Verbesserte Fehlerbehandlung und Protokollierung in `Form1.vb`, `WindowsService.vb` und anderen Klassen.
- Konsistente Verwendung von Symbolen (✔, ⚠) zur Hervorhebung von Erfolgen und Warnungen.
- Aktualisierung der `Settings.settings` und Bereinigung nicht mehr benötigter Konfigurationswerte.
- Downgrade von `Microsoft.Data.SqlClient` von Version 7.0.1 auf 5.2.2.
- Entfernung redundanter Module und Codeabschnitte zur Verbesserung der Wartbarkeit.
- Verbesserte Fehlerbehandlung beim Starten und Stoppen des ServiceHosts.
- Optimierung der Protokollmeldungen für Debugging und Performance-Analysen.
This commit is contained in:
Developer01
2026-09-22 16:42:07 +02:00
parent 0f9e7c55ec
commit 9901b48b80
12 changed files with 136 additions and 140 deletions

View File

@@ -61,34 +61,38 @@ Public Class WindowsService
oTimer.Start()
' Setting Debug Flag
Logger.Info("Setting DEBUG Flag to [{0}]", ConfigManager.Config.Debug)
If ConfigManager.Config.Debug Then
Logger.Info("Debug Flag is set to TRUE. Logging will be more verbose.")
Else
Logger.Info("Debug Flag is set to FALSE. Logging will be less verbose.")
End If
LogConfig.Debug = ConfigManager.Config.Debug
LogConfigScheduler.Debug = ConfigManager.Config.Debug
Logger.Info("Connecting to Databases..")
Logger.Debug("Connecting to Databases...")
Firebird = StartFirebird()
MSSQL_ECM = GetMSSQL_ECM(LogConfig)
MSSQL_IDB = GetMSSQL_IDB(LogConfig)
MSSQL_Config = GetMSSQL_Config(LogConfig)
Logger.Info("Connection to Databases established!")
Logger.Debug("Connection to Databases established!")
Logger.Debug("Initializing EDMI Functions")
Logger.Debug("Initializing EDMI Functions...")
Filesystem = New Filesystem.File(LogConfig)
GlobalState = New GlobalState(LogConfig, MSSQL_IDB, MSSQL_ECM)
Dim oMSSQLServer = GetMSSQL_Config(LogConfigScheduler)
Scheduler = New Scheduler(LogConfigScheduler, oMSSQLServer, GlobalState.TableStore, GlobalState)
Logger.Info("Loading Global Data")
Logger.Debug("Loading Global Data ...")
GlobalState.LoadObjectStores()
GlobalState.LoadConnections()
GlobalState.LoadDoctypes()
GlobalState.LoadClientConfig(Config)
Logger.Info("Starting Scheduler")
Logger.Debug("Starting Scheduler ...")
Scheduler.Start()
Logger.Info("Preparing WCF ServiceHost")
Logger.Debug("Preparing WCF ServiceHost ...")
EDMIService.MSSQL_ECM = MSSQL_ECM
EDMIService.MSSQL_IDB = MSSQL_IDB
EDMIService.Firebird = Firebird
@@ -97,11 +101,20 @@ Public Class WindowsService
EDMIService.GlobalState = GlobalState
EDMIService.Scheduler = Scheduler
Logger.Info("Starting WCF ServiceHost")
Logger.Debug("Starting WCF ServiceHost ...")
Dim oBaseAddresses() As Uri = {New Uri(SERVICE_BASE_ADDRESS)}
ServiceHost = New ServiceHost(Of EDMIService)(oBaseAddresses)
ServiceHost.EnableMetadataExchange(False)
' MEX-Endpoints explizit entfernen, da sie Port-Konflikte verursachen
Dim oMexEndpoints = ServiceHost.Description.Endpoints _
.Where(Function(e) e.Contract.ContractType = GetType(IMetadataExchange)) _
.ToList()
For Each oEndpoint In oMexEndpoints
ServiceHost.Description.Endpoints.Remove(oEndpoint)
Logger.Debug("OnStart -> Removed MEX endpoint: {0}", oEndpoint.Address.ToString)
Next
Logger.Debug("Listing Endpoints:")
For Each oEndpoint In ServiceHost.Description.Endpoints
@@ -113,12 +126,20 @@ Public Class WindowsService
Next
Logger.Debug("Starting WFC ServiceHost..")
ServiceHost.Open()
Logger.Debug("WCF ServiceHost started!")
Logger.Info("Service {0} successfully started!", SERVICE_DISPLAY_NAME)
Try
ServiceHost.Open()
Logger.Debug("WCF ServiceHost started!")
Catch ex As System.ServiceModel.AddressAlreadyInUseException
Logger.Error("Port is already in use! Check if another instance is running. Details: {0}", ex.Message)
GracefullyStop()
Catch ex As Exception
Logger.Warn("⚠ Unexpected error while opening ServiceHost: {0}", ex.Message)
Logger.Error(ex)
GracefullyStop()
End Try
Logger.Info("✔ Service [{0}] started successfully!", SERVICE_DISPLAY_NAME)
Catch ex As Exception
Logger.Warn("Unexpected Error while starting the service: {0}", ex.Message)
Logger.Warn("⚠ Unexpected Error while starting the service: {0}", ex.Message)
Logger.Error(ex)
GracefullyStop()
End Try
@@ -126,7 +147,7 @@ Public Class WindowsService
Private Sub ReloadTimer_Tick()
If ConfigManager.Reload() = False Then
Logger.Warn("Could not reload config, check the service and config file.")
Logger.Warn("⚠ Could not reload config, check the service and config file.")
End If
Config = ConfigManager.Config
@@ -153,7 +174,7 @@ Public Class WindowsService
Logger.Info("Database connection established.")
Return oFirebird
Catch ex As Exception
Logger.Warn("StartFirebird: Could not connect to firebird database.")
Logger.Warn("⚠ StartFirebird: Could not connect to firebird database.")
Logger.Error(ex)
Return Nothing
End Try
@@ -162,41 +183,41 @@ Public Class WindowsService
Private Function GetMSSQL_ECM(pLogConfig As LogConfig) As MSSQLServer
Logger.Debug("Connecting to ECM MSSQL")
If Config.ConnectionString_ECM = String.Empty Then
Logger.Warn("Configuration for ConnectionString_ECM is missing.")
Logger.Warn("⚠ Configuration for ConnectionString_ECM is missing.")
Throw New ArgumentNullException("ConnectionString_ECM")
End If
Dim oMSSQL = New MSSQLServer(pLogConfig, Config.ConnectionString_ECM)
Logger.Info("Database connection to ECM Database established.")
Logger.Info("✔ Database connection to ECM Database established.")
Return oMSSQL
End Function
Private Function GetMSSQL_IDB(pLogConfig As LogConfig) As MSSQLServer
Logger.Debug("Connecting to IDB MSSQL")
If Config.ConnectionString_IDB = String.Empty Then
Logger.Warn("Configuration for ConnectionString_IDB is missing.")
Logger.Warn("⚠ Configuration for ConnectionString_IDB is missing.")
Throw New ArgumentNullException("ConnectionString_IDB")
End If
Dim oMSSQL = New MSSQLServer(pLogConfig, Config.ConnectionString_IDB)
Logger.Info("Database connection to IDB Database established.")
Logger.Info("✔ Database connection to IDB Database established.")
Return oMSSQL
End Function
Private Function GetMSSQL_Config(pLogConfig As LogConfig) As MSSQLServer
Logger.Debug("Connecting to Config MSSQL")
Logger.Debug("Connecting to Config MSSQL...")
If Config.ConnectionString_Config = String.Empty Then
If Config.ConnectionString_ECM <> String.Empty Then
Logger.Info("Using ConnectionString_ECM for Config Database connection.")
Logger.Debug("Using ConnectionString_ECM for Config Database connection!")
Return GetMSSQL_ECM(pLogConfig)
Else
Logger.Warn("Configuration for ConnectionString_Config is missing and ConnectionString_ECM is also missing.")
Logger.Warn("⚠ Configuration for ConnectionString_Config is missing and ConnectionString_ECM is also missing.")
Throw New ArgumentNullException("ConnectionString_Config")
End If
End If
Dim oMSSQL = New MSSQLServer(pLogConfig, Config.ConnectionString_Config)
Logger.Info("Database connection to Config Database established.")
Logger.Info("✔ Database connection to Config Database established.")
Return oMSSQL
End Function
@@ -205,13 +226,28 @@ Public Class WindowsService
End Sub
Private Sub GracefullyStop()
Logger.Info("Service {0} is stopping!", SERVICE_DISPLAY_NAME)
Logger.Info("GracefullyStop - Service {0} is stopping!", SERVICE_DISPLAY_NAME)
If ServiceHost IsNot Nothing Then
ServiceHost.Close()
ServiceHost = Nothing
Try
If ServiceHost.State = CommunicationState.Faulted Then
Logger.Warn("⚠ GracefullyStop - ServiceHost is in Faulted state. Using Abort() instead of Close().")
ServiceHost.Abort()
Else
ServiceHost.Close()
End If
Catch ex As Exception
Logger.Warn("⚠ GracefullyStop - Error while closing ServiceHost: {0}", ex.Message)
Logger.Error(ex)
ServiceHost.Abort()
Finally
ServiceHost = Nothing
End Try
End If
Scheduler.Stop()
If Scheduler IsNot Nothing Then
Logger.Info("GracefullyStop - Stopping Scheduler.")
Scheduler.Stop()
End If
End Sub
End Class