Remove ClassLogger and replace with Logging Module
This commit is contained in:
parent
27294faa13
commit
e81f2f0878
@ -20,12 +20,9 @@ Public Class ClassEmail
|
|||||||
My.Computer.Clock.LocalTime.ToLongTimeString & "</font>")
|
My.Computer.Clock.LocalTime.ToLongTimeString & "</font>")
|
||||||
If test = False Then
|
If test = False Then
|
||||||
If Log = True Then
|
If Log = True Then
|
||||||
' create and add the attachment(s) */
|
' create and add the attachment(s) */
|
||||||
If ClassLogger.logDateiname.Contains("\\") Then
|
If IO.File.Exists(LOGCONFIG.LogFile) Then
|
||||||
ClassLogger.logDateiname = ClassLogger.logDateiname.Replace("\\", "\")
|
Dim Attachment As Attachment = New Attachment(LOGCONFIG.LogFile)
|
||||||
End If
|
|
||||||
If IO.File.Exists(ClassLogger.logDateiname) Then
|
|
||||||
Dim Attachment As Attachment = New Attachment(ClassLogger.logDateiname)
|
|
||||||
message.Attachments.Add(Attachment)
|
message.Attachments.Add(Attachment)
|
||||||
End If
|
End If
|
||||||
End If
|
End If
|
||||||
|
|||||||
@ -9,7 +9,6 @@ Imports DLLLicenseManager
|
|||||||
|
|
||||||
Public Class ClassInit
|
Public Class ClassInit
|
||||||
Public Sub InitLogger()
|
Public Sub InitLogger()
|
||||||
ClassLogger.Init("", Environment.UserName)
|
|
||||||
LOGCONFIG = New LogConfig(LogConfig.PathType.AppData, Nothing, Nothing,
|
LOGCONFIG = New LogConfig(LogConfig.PathType.AppData, Nothing, Nothing,
|
||||||
CompanyName:=My.Application.Info.CompanyName,
|
CompanyName:=My.Application.Info.CompanyName,
|
||||||
ProductName:=My.Application.Info.ProductName)
|
ProductName:=My.Application.Info.ProductName)
|
||||||
|
|||||||
@ -1,215 +0,0 @@
|
|||||||
Imports System.IO
|
|
||||||
Public Class ClassLogger
|
|
||||||
Public Shared DateiSpeicherort As String = Nothing
|
|
||||||
Public Shared DateiPrefix As String = ""
|
|
||||||
Public Shared Datei As IO.File = Nothing
|
|
||||||
Public Shared logDateiname As String = ""
|
|
||||||
Private Shared StreamWriter As IO.StreamWriter = Nothing
|
|
||||||
Private Shared HasInformedAboutError As Boolean = False
|
|
||||||
' eine Art Konstruktor
|
|
||||||
Public Shared Sub Init(ByVal speicherort As String, Optional ByVal prefix As String = "", Optional ByVal appendFile As Boolean = True)
|
|
||||||
' initialisiert den Speicherort
|
|
||||||
ClassLogger.SetSpeicherort(speicherort)
|
|
||||||
' wenn ein Prfix gesetzt wurde
|
|
||||||
If Not prefix = "" Then
|
|
||||||
' initialisiert das Prefix
|
|
||||||
ClassLogger.SetPrefix(prefix)
|
|
||||||
End If
|
|
||||||
Dim str As String = ClassLogger.DateiSpeicherort & "\" & ClassLogger.DateiPrefix & System.DateTime.Now.ToString("yyyy_MM_dd") & ".txt"
|
|
||||||
Dim anz As Integer = 1
|
|
||||||
Do While File.Exists(str)
|
|
||||||
Dim info As New FileInfo(str)
|
|
||||||
Dim length As Long = info.Length
|
|
||||||
If length > 5000000 Then
|
|
||||||
str = IO.Path.GetDirectoryName(str)
|
|
||||||
str = str & "\" & ClassLogger.DateiPrefix & System.DateTime.Now.ToString("yyyy_MM_dd") & "(" & anz.ToString & ").txt"
|
|
||||||
anz = anz + 1
|
|
||||||
Else
|
|
||||||
Exit Do
|
|
||||||
End If
|
|
||||||
Loop
|
|
||||||
ClassLogger.logDateiname = str
|
|
||||||
If Not appendFile Then
|
|
||||||
' der Versuch die Datei zu löschen
|
|
||||||
'Try
|
|
||||||
' My.Computer.FileSystem.DeleteFile(ClassNILogger.Dateiname, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
|
|
||||||
'Catch ex As Exception
|
|
||||||
' ' bei Fehler besteht kein Schreibrecht auf die Datei oder Datei existiert nicht
|
|
||||||
' ' ALSO: alles Okay soweit
|
|
||||||
'End Try
|
|
||||||
My.Computer.FileSystem.WriteAllText(ClassLogger.logDateiname, String.Empty, False)
|
|
||||||
End If
|
|
||||||
' testen ob sich die Datei öffnen und beschreiben lässt
|
|
||||||
'ClassNILogger.CheckIsLogWritable()
|
|
||||||
End Sub
|
|
||||||
|
|
||||||
' legt den Speicherort fest
|
|
||||||
Public Shared Sub SetSpeicherort(ByVal speicherort As String)
|
|
||||||
Dim f As New IO.DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Digital Data\Global Indexer\Log"))
|
|
||||||
|
|
||||||
If speicherort = "" Then
|
|
||||||
If f.Exists = False Then
|
|
||||||
IO.Directory.CreateDirectory(f.ToString())
|
|
||||||
End If
|
|
||||||
ClassLogger.DateiSpeicherort = f.ToString()
|
|
||||||
Else
|
|
||||||
ClassLogger.DateiSpeicherort = speicherort
|
|
||||||
End If
|
|
||||||
|
|
||||||
'Dim f As New IO.DirectoryInfo(My.Application.Info.DirectoryPath & "\Log")
|
|
||||||
'If speicherort = "" Then
|
|
||||||
' If f.Exists = False Then
|
|
||||||
' IO.Directory.CreateDirectory(My.Application.Info.DirectoryPath & "\Log")
|
|
||||||
' End If
|
|
||||||
' ClassLogger.DateiSpeicherort = My.Application.Info.DirectoryPath & "\Log\"
|
|
||||||
'Else
|
|
||||||
' ClassLogger.DateiSpeicherort = speicherort
|
|
||||||
'End If
|
|
||||||
End Sub
|
|
||||||
|
|
||||||
' legt das Prefix für den Dateinamen fest
|
|
||||||
Public Shared Sub SetPrefix(ByVal prefix As String)
|
|
||||||
ClassLogger.DateiPrefix = prefix
|
|
||||||
End Sub
|
|
||||||
|
|
||||||
Public Shared Sub Add(ByVal information As String, Optional ByVal ACHTUNG As Boolean = True)
|
|
||||||
If ClassLogger.OpenFile Then
|
|
||||||
Try
|
|
||||||
If ACHTUNG Then
|
|
||||||
ClassLogger.StreamWriter.WriteLine(Now.ToString & "# ATTENTION #: " & information)
|
|
||||||
Else
|
|
||||||
ClassLogger.StreamWriter.WriteLine(Now.ToString & information)
|
|
||||||
End If
|
|
||||||
ClassLogger.CloseFile()
|
|
||||||
Catch e As Exception
|
|
||||||
ClassLogger.ShowErrorMessage()
|
|
||||||
End Try
|
|
||||||
Else
|
|
||||||
ClassLogger.ShowErrorMessage()
|
|
||||||
End If
|
|
||||||
End Sub
|
|
||||||
Public Shared Sub Add(ByVal ex As Exception)
|
|
||||||
If ClassLogger.OpenFile Then
|
|
||||||
Try
|
|
||||||
ClassLogger.StreamWriter.WriteLine(Now.ToString & "##### Exception ####")
|
|
||||||
ClassLogger.StreamWriter.WriteLine(Now.ToString & "##### Fehler: " & ex.Message & " Source [" & ex.Source & "]")
|
|
||||||
ClassLogger.CloseFile()
|
|
||||||
Catch e As Exception
|
|
||||||
ClassLogger.ShowErrorMessage()
|
|
||||||
End Try
|
|
||||||
Else
|
|
||||||
ClassLogger.ShowErrorMessage()
|
|
||||||
End If
|
|
||||||
End Sub
|
|
||||||
' öffnet eine Datei zum Schreiben
|
|
||||||
Private Shared Function OpenFile()
|
|
||||||
Try
|
|
||||||
' wenn ein Speicherort festgelegt wurde
|
|
||||||
If Not ClassLogger.DateiSpeicherort = Nothing Then
|
|
||||||
' den Dateienamen definieren
|
|
||||||
Dim dateiname As String = ClassLogger.logDateiname
|
|
||||||
' Datei anlegen wenn noch nicht vorhanden
|
|
||||||
My.Computer.FileSystem.WriteAllText(dateiname, String.Empty, True)
|
|
||||||
' die Datei zum Schreiben öffnen
|
|
||||||
ClassLogger.StreamWriter = New IO.StreamWriter(dateiname, True, System.Text.Encoding.UTF8)
|
|
||||||
End If
|
|
||||||
' wenn die Datei erfolgreich geöffnet wurde
|
|
||||||
If ClassLogger.StreamWriter IsNot Nothing Then
|
|
||||||
Return True
|
|
||||||
Else
|
|
||||||
Return False
|
|
||||||
End If
|
|
||||||
Catch ex As Exception
|
|
||||||
Return False
|
|
||||||
End Try
|
|
||||||
|
|
||||||
End Function
|
|
||||||
|
|
||||||
' öffnet eine Datei zum Schreiben
|
|
||||||
Private Shared Function OpenFile(ByVal DateiSpeicherort As String, ByVal DateiPrefix As String)
|
|
||||||
|
|
||||||
Try
|
|
||||||
|
|
||||||
' wenn ein Speicherort festgelegt wurde
|
|
||||||
If Not DateiSpeicherort = Nothing And ClassLogger.CheckIsLogWritable() Then
|
|
||||||
|
|
||||||
' den Dateienamen definieren
|
|
||||||
Dim dateiname As String = ClassLogger.logDateiname
|
|
||||||
' Datei anlegen wenn noch nicht vorhanden
|
|
||||||
My.Computer.FileSystem.WriteAllText(dateiname, String.Empty, True)
|
|
||||||
|
|
||||||
' die Datei zum Schreiben öffnen
|
|
||||||
ClassLogger.StreamWriter = New IO.StreamWriter(dateiname, True, System.Text.Encoding.UTF8)
|
|
||||||
End If
|
|
||||||
|
|
||||||
' wenn die Datei erfolgreich geöffnet wurde
|
|
||||||
If ClassLogger.StreamWriter IsNot Nothing Then
|
|
||||||
Return True
|
|
||||||
Else
|
|
||||||
Return False
|
|
||||||
End If
|
|
||||||
|
|
||||||
Catch ex As Exception
|
|
||||||
Return False
|
|
||||||
End Try
|
|
||||||
|
|
||||||
End Function
|
|
||||||
|
|
||||||
|
|
||||||
' schliesst die geöffnete Datei
|
|
||||||
Private Shared Sub CloseFile()
|
|
||||||
|
|
||||||
' wenn eine Datei geöffnet ist
|
|
||||||
If ClassLogger.StreamWriter IsNot Nothing Then
|
|
||||||
' die Datei schliessen
|
|
||||||
ClassLogger.StreamWriter.Close()
|
|
||||||
ClassLogger.StreamWriter = Nothing
|
|
||||||
End If
|
|
||||||
End Sub
|
|
||||||
|
|
||||||
|
|
||||||
Public Shared Function CheckIsLogWritable()
|
|
||||||
|
|
||||||
If ClassLogger.OpenFile Then
|
|
||||||
Try
|
|
||||||
ClassLogger.CloseFile()
|
|
||||||
Catch e As Exception
|
|
||||||
ClassLogger.ShowErrorMessage()
|
|
||||||
Return False
|
|
||||||
End Try
|
|
||||||
Else
|
|
||||||
ClassLogger.ShowErrorMessage()
|
|
||||||
Return False
|
|
||||||
End If
|
|
||||||
|
|
||||||
Return True
|
|
||||||
End Function
|
|
||||||
|
|
||||||
|
|
||||||
Public Shared Function CheckIsLogWritable(ByVal vDateiSpeicherort As String, ByVal vDateiPrefix As String)
|
|
||||||
|
|
||||||
If ClassLogger.OpenFile(vDateiSpeicherort, vDateiPrefix) Then
|
|
||||||
Try
|
|
||||||
ClassLogger.CloseFile()
|
|
||||||
Catch e As Exception
|
|
||||||
ClassLogger.ShowErrorMessage()
|
|
||||||
Return False
|
|
||||||
End Try
|
|
||||||
Else
|
|
||||||
ClassLogger.ShowErrorMessage()
|
|
||||||
Return False
|
|
||||||
End If
|
|
||||||
|
|
||||||
Return True
|
|
||||||
End Function
|
|
||||||
|
|
||||||
|
|
||||||
Private Shared Sub ShowErrorMessage()
|
|
||||||
If Not ClassLogger.HasInformedAboutError Then
|
|
||||||
MsgBox("Beim Öffnen der Logdatei ist ein Fehler aufgetreten. Bitte stellen Sie sicher das Sie sowohl über entsprechende Schreibrechte im Verzeichnis, als auch über ausreichend Speicherplatz zum Speichern der Logdatei verfügen." & _
|
|
||||||
vbNewLine & vbNewLine & "Es wird keine Logdatei angelegt oder beschrieben." & vbNewLine & vbNewLine & "Im folgenden werden Sie über Fehler, den Log betreffend nicht weiter informiert, um den Ablauf von " & My.Application.Info.ProductName & " nicht zu stören.", _
|
|
||||||
MsgBoxStyle.Information, "Unexpected error inm Öffnen der Logdatei")
|
|
||||||
ClassLogger.HasInformedAboutError = True
|
|
||||||
End If
|
|
||||||
End Sub
|
|
||||||
End Class
|
|
||||||
@ -269,7 +269,6 @@
|
|||||||
<Compile Include="ClassInit.vb" />
|
<Compile Include="ClassInit.vb" />
|
||||||
<Compile Include="ClassLayout.vb" />
|
<Compile Include="ClassLayout.vb" />
|
||||||
<Compile Include="ClassLicence.vb" />
|
<Compile Include="ClassLicence.vb" />
|
||||||
<Compile Include="ClassLogger.vb" />
|
|
||||||
<Compile Include="ClassParamRefresh.vb" />
|
<Compile Include="ClassParamRefresh.vb" />
|
||||||
<Compile Include="ClassPatterns.vb" />
|
<Compile Include="ClassPatterns.vb" />
|
||||||
<Compile Include="ClassPostprocessing.vb" />
|
<Compile Include="ClassPostprocessing.vb" />
|
||||||
|
|||||||
@ -404,7 +404,7 @@ Public Class frmConfig_Basic
|
|||||||
|
|
||||||
End Sub
|
End Sub
|
||||||
Private Sub btnopenlog_Click(sender As Object, e As EventArgs) Handles btnopenlog.Click
|
Private Sub btnopenlog_Click(sender As Object, e As EventArgs) Handles btnopenlog.Click
|
||||||
Process.Start(ClassLogger.DateiSpeicherort)
|
Process.Start(LOGCONFIG.LogDirectory)
|
||||||
End Sub
|
End Sub
|
||||||
Private Sub btnApplicationFolder_Click(sender As Object, e As EventArgs) Handles btnApplicationFolder.Click
|
Private Sub btnApplicationFolder_Click(sender As Object, e As EventArgs) Handles btnApplicationFolder.Click
|
||||||
Process.Start(Application.UserAppDataPath())
|
Process.Start(Application.UserAppDataPath())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user