jj: Update TesTGUI & EDM Designer
This commit is contained in:
@@ -1,179 +0,0 @@
|
||||
Imports NLog
|
||||
Imports NLog.Config
|
||||
Imports NLog.Targets
|
||||
Imports NLog.Targets.Wrappers
|
||||
Imports NLog.Targets.Wrappers.BufferingTargetWrapperOverflowAction
|
||||
|
||||
Imports System.IO
|
||||
|
||||
Public Class ClassLogger
|
||||
Private Const FileNameFormat As String = "${shortdate}-${var:product}.log"
|
||||
Private Const FileNameFormatDetail As String = "${shortdate}-${var:product}-Detail.log"
|
||||
Private Const FileNameFormatDebug As String = "${shortdate}-${var:product}-Debug.log"
|
||||
|
||||
Private Const TARGET_DEFAULT As String = "default"
|
||||
Private Const TARGET_DEFAULT_EX As String = "defaultEx"
|
||||
Private Const TARGET_DETAIL As String = "detail"
|
||||
Private Const TARGET_DEBUG As String = "debug"
|
||||
|
||||
Private Const defaultLogFormat As String = "${longdate}|${level:uppercase=true}|${logger}|${message}"
|
||||
Private Const exceptionLogFormat As String = "${longdate}|${level:uppercase=true}|${logger}|${message}|${exception:format=message}|${exception:format=toString}"
|
||||
|
||||
Private config As LoggingConfiguration
|
||||
Private debugOn As Boolean = False
|
||||
|
||||
Private ReadOnly failSafePath As String = Path.GetTempPath()
|
||||
Private ReadOnly basePath As String = failSafePath
|
||||
|
||||
Public Enum PathType As Integer
|
||||
AppData = 0
|
||||
CurrentDirectory = 1
|
||||
CustomPath = 2
|
||||
End Enum
|
||||
|
||||
Public LogFile As String
|
||||
|
||||
|
||||
Public Property Debug As Boolean
|
||||
Get
|
||||
Return debugOn
|
||||
End Get
|
||||
Set(value As Boolean)
|
||||
If debugOn <> value Then
|
||||
debugOn = value
|
||||
|
||||
If value = True Then
|
||||
ActivateDebugLog()
|
||||
Else
|
||||
DeactivateDebugLog()
|
||||
End If
|
||||
End If
|
||||
End Set
|
||||
End Property
|
||||
|
||||
''' <summary>
|
||||
''' Initializes a new Logger for a specific "Product"
|
||||
''' </summary>
|
||||
''' <param name="product">An name that identifies the Logs</param>
|
||||
''' <param name="logPath">The basepath to write logs to. Can be AppData, CurrentDirectory or CustomPath.</param>
|
||||
''' <param name="customLogPath">If `logPath` is set to custom, this defines the custom logPath</param>
|
||||
Public Sub New(product As String, logPath As PathType, Optional customLogPath As String = Nothing)
|
||||
If logPath = PathType.AppData Then
|
||||
Dim appDataDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
|
||||
basePath = Path.Combine(appDataDir, "Digital Data", product)
|
||||
ElseIf logPath = PathType.CurrentDirectory Then
|
||||
basePath = "Log"
|
||||
Else 'Custom Path
|
||||
basePath = customLogPath
|
||||
End If
|
||||
|
||||
config = New LoggingConfiguration()
|
||||
config.Variables("product") = product
|
||||
|
||||
config.AddTarget(TARGET_DEFAULT_EX, WrapTargetInBuffered(GetDefaultLogTargetWithExceptions(basePath)))
|
||||
config.AddTarget(TARGET_DEFAULT, WrapTargetInBuffered(GetDefaultLogTarget(basePath)))
|
||||
config.AddTarget(TARGET_DETAIL, WrapTargetInBuffered(GetDetailLogTarget(basePath)))
|
||||
config.AddTarget(TARGET_DEBUG, WrapTargetInBuffered(GetDebugLogTarget(basePath)))
|
||||
|
||||
AddDefaultLogTargets()
|
||||
|
||||
LogManager.Configuration = config
|
||||
End Sub
|
||||
|
||||
Private Function WrapTargetInBuffered(target As FileTarget) As Target
|
||||
Dim bufferedWrapper = New BufferingTargetWrapper()
|
||||
|
||||
bufferedWrapper.WrappedTarget = target
|
||||
|
||||
' Number of log events to be buffered. When the limit is reached,
|
||||
' then a synchronous flush is performed.
|
||||
bufferedWrapper.BufferSize = 100
|
||||
|
||||
' Action to be taken when the buffer exceeds the set bufferSize.
|
||||
bufferedWrapper.OverflowAction = Flush
|
||||
|
||||
' Timeout (in milliseconds) after a write, until the entire buffer
|
||||
' is asynchronously flushed. Use -1 to disable timed flushes.
|
||||
bufferedWrapper.FlushTimeout = 100
|
||||
|
||||
Return bufferedWrapper
|
||||
End Function
|
||||
|
||||
|
||||
Private Sub ActivateDebugLog()
|
||||
' Clear Logging Rules
|
||||
config.LoggingRules.Clear()
|
||||
|
||||
' Add default targets and debug target
|
||||
AddDefaultLogTargets()
|
||||
config.AddRuleForOneLevel(LogLevel.Debug, TARGET_DEBUG)
|
||||
|
||||
' Reload all running loggers
|
||||
LogManager.ReconfigExistingLoggers()
|
||||
End Sub
|
||||
|
||||
Private Sub DeactivateDebugLog()
|
||||
' Clear Logging Rules
|
||||
config.LoggingRules.Clear()
|
||||
|
||||
' Add default targets
|
||||
AddDefaultLogTargets()
|
||||
|
||||
' Reload all running loggers
|
||||
LogManager.ReconfigExistingLoggers()
|
||||
End Sub
|
||||
|
||||
Private Sub AddDefaultLogTargets()
|
||||
config.AddRuleForOneLevel(LogLevel.Error, TARGET_DEFAULT_EX)
|
||||
config.AddRuleForOneLevel(LogLevel.Fatal, TARGET_DEFAULT_EX)
|
||||
config.AddRuleForOneLevel(LogLevel.Warn, TARGET_DEFAULT)
|
||||
config.AddRuleForOneLevel(LogLevel.Info, TARGET_DETAIL)
|
||||
End Sub
|
||||
|
||||
#Region "Log Targets"
|
||||
Private Function GetDefaultLogTarget(basePath As String) As FileTarget
|
||||
Dim defaultFilePath As String = Path.Combine(basePath, FileNameFormat)
|
||||
Dim defaultLog As New FileTarget() With {
|
||||
.FileName = defaultFilePath,
|
||||
.Layout = defaultLogFormat,
|
||||
.MaxArchiveFiles = 30,
|
||||
.KeepFileOpen = True
|
||||
}
|
||||
|
||||
Return defaultLog
|
||||
End Function
|
||||
Private Function GetDefaultLogTargetWithExceptions(basePath As String) As FileTarget
|
||||
Dim defaultFilePath As String = Path.Combine(basePath, FileNameFormat)
|
||||
Dim defaultLogWithExceptionData As New FileTarget() With {
|
||||
.FileName = defaultFilePath,
|
||||
.Layout = exceptionLogFormat,
|
||||
.MaxArchiveFiles = 30,
|
||||
.KeepFileOpen = True
|
||||
}
|
||||
|
||||
Return defaultLogWithExceptionData
|
||||
End Function
|
||||
Private Function GetDetailLogTarget(basePath As String) As FileTarget
|
||||
Dim detailFilePath As String = Path.Combine(basePath, FileNameFormatDetail)
|
||||
Dim detailLog As New FileTarget() With {
|
||||
.FileName = detailFilePath,
|
||||
.Layout = defaultLogFormat,
|
||||
.MaxArchiveFiles = 1,
|
||||
.KeepFileOpen = True
|
||||
}
|
||||
|
||||
Return detailLog
|
||||
End Function
|
||||
Private Function GetDebugLogTarget(basePath As String) As FileTarget
|
||||
Dim debugFilePath As String = Path.Combine(basePath, FileNameFormatDebug)
|
||||
Dim debugLog As New FileTarget() With {
|
||||
.FileName = debugFilePath,
|
||||
.Layout = defaultLogFormat,
|
||||
.MaxArchiveFiles = 1,
|
||||
.KeepFileOpen = True
|
||||
}
|
||||
|
||||
Return debugLog
|
||||
End Function
|
||||
#End Region
|
||||
End Class
|
||||
@@ -111,7 +111,6 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="ClassCurrentUser.vb" />
|
||||
<Compile Include="ClassInit.vb" />
|
||||
<Compile Include="ClassLogger.vb" />
|
||||
<Compile Include="FrmConnection.Designer.vb">
|
||||
<DependentUpon>FrmConnection.vb</DependentUpon>
|
||||
</Compile>
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Public Class FrmConnection
|
||||
Public Property LogFactory As NLog.LogFactory
|
||||
Public Property LogConfig As LogConfig
|
||||
|
||||
Private _logger As NLog.Logger
|
||||
|
||||
Private Sub FrmConnection_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
||||
_logger = LogFactory.GetCurrentClassLogger()
|
||||
_logger = LogConfig.GetLogger()
|
||||
|
||||
FbDatabaseLocationTextBox.DataBindings.Add("Text", My.Settings, "fbDatabaseLocation")
|
||||
FbDatasourceTextBox.DataBindings.Add("Text", My.Settings, "fbDatasource")
|
||||
@@ -18,7 +19,7 @@ Public Class FrmConnection
|
||||
Dim dbTest As Firebird
|
||||
|
||||
Try
|
||||
dbTest = New Firebird(LogFactory, My.Settings.fbDatasource, My.Settings.fbDatabaseLocation, My.Settings.fbUser, My.Settings.fbPassword)
|
||||
dbTest = New Firebird(LogConfig, My.Settings.fbDatasource, My.Settings.fbDatabaseLocation, My.Settings.fbUser, My.Settings.fbPassword)
|
||||
|
||||
If dbTest.ConnectionFailed Then
|
||||
MsgBox("Connection failed!", MsgBoxStyle.Information, "Database Connection")
|
||||
|
||||
@@ -6,7 +6,7 @@ Public Class FrmMain
|
||||
Private _selectedTable As Integer
|
||||
Private _selectedTableName As String
|
||||
|
||||
Private _logger As NLog.Logger
|
||||
Private _logger As Logger
|
||||
Private _logConfig As LogConfig
|
||||
Private _firebird As Firebird
|
||||
|
||||
@@ -56,7 +56,7 @@ Public Class FrmMain
|
||||
End Function
|
||||
|
||||
Private Sub Init()
|
||||
_firebird = New Firebird(_logConfig.LogFactory, My.Settings.fbDatasource, My.Settings.fbDatabaseLocation, My.Settings.fbUser, My.Settings.fbPassword)
|
||||
_firebird = New Firebird(_logConfig, My.Settings.fbDatasource, My.Settings.fbDatabaseLocation, My.Settings.fbUser, My.Settings.fbPassword)
|
||||
|
||||
If _firebird.ConnectionFailed Then
|
||||
MsgBox("Database connection failed. Please check the log.", vbCritical)
|
||||
@@ -72,13 +72,25 @@ Public Class FrmMain
|
||||
End Sub
|
||||
|
||||
Private Sub FrmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
|
||||
_logConfig = New LogConfig(ClassLogger.PathType.CurrentDirectory)
|
||||
_logger = _logConfig.LogFactory.GetCurrentClassLogger()
|
||||
_logConfig = New LogConfig(LogConfig.PathType.CurrentDirectory)
|
||||
_logger = _logConfig.GetLogger() '_logConfig.LogFactory.GetCurrentClassLogger(GetType(Logger))
|
||||
|
||||
_logger.NewBlock("STARTUP")
|
||||
_logger.Info("INFO")
|
||||
_logger.Warn("WARN")
|
||||
_logger.NewBlock("ERROR")
|
||||
|
||||
|
||||
Try
|
||||
Throw New Exception("ERROR")
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
End Try
|
||||
|
||||
' Check for existing database credentials
|
||||
While Not DatabaseSettingsExist()
|
||||
Dim form As New FrmConnection With {
|
||||
.LogFactory = _logConfig.LogFactory
|
||||
.LogConfig = _logConfig
|
||||
}
|
||||
Dim result As DialogResult = form.ShowDialog()
|
||||
|
||||
@@ -151,7 +163,7 @@ Public Class FrmMain
|
||||
End Sub
|
||||
|
||||
Private Sub NeueTabelleToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NeueTabelleToolStripMenuItem.Click
|
||||
Dim oForm As New FrmNewTable(_logConfig.LogFactory)
|
||||
Dim oForm As New FrmNewTable(_logConfig)
|
||||
oForm.ShowDialog()
|
||||
|
||||
Dim oTables As DataTable = LoadTables()
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
Imports NLog
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
|
||||
Public Class FrmNewTable
|
||||
Private _logFactory As LogFactory
|
||||
Private _logConfig As LogConfig
|
||||
Private _logger As Logger
|
||||
Private _db As Firebird
|
||||
|
||||
Public Sub New(LogFactory As LogFactory)
|
||||
Public Sub New(LogConfig As LogConfig)
|
||||
' Dieser Aufruf ist für den Designer erforderlich.
|
||||
InitializeComponent()
|
||||
|
||||
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
|
||||
_logFactory = LogFactory
|
||||
_logger = _logFactory.GetCurrentClassLogger()
|
||||
_logConfig = LogConfig
|
||||
_logger = _logConfig.GetLogger()
|
||||
End Sub
|
||||
|
||||
Private Sub FrmNewTable_Load(sender As Object, e As EventArgs) Handles Me.Load
|
||||
Try
|
||||
_db = New Firebird(_logFactory, My.Settings.fbDatasource, My.Settings.fbDatabaseLocation, My.Settings.fbUser, My.Settings.fbPassword)
|
||||
_db = New Firebird(_logConfig, My.Settings.fbDatasource, My.Settings.fbDatabaseLocation, My.Settings.fbUser, My.Settings.fbPassword)
|
||||
Catch ex As Exception
|
||||
MsgBox("Connection to DB failed!", MsgBoxStyle.Critical)
|
||||
_logger.Error(ex)
|
||||
|
||||
Reference in New Issue
Block a user