Files
SDL/VERAG_PROG_ALLGEMEIN/cErrorHandler.vb
2021-10-27 11:19:22 +02:00

77 lines
3.1 KiB
VB.net

Imports System.Net.Mail
Public Class cErrorHandler
Public Shared Sub ERR(message As String, stack As String, functionName As String, Optional OP As String = "", Optional title As String = "", Optional mailadess As String = "al@verag.ag", Optional recieverMailAdress As String = "", Optional zusatz As String = "", Optional errCode As String = Nothing)
If OP = "" Then OP = VERAG_PROG_ALLGEMEIN.cAllgemein.ERR_OP_GLOBAL ' GLobal gesetzes Errorhandling! (Standart=SHOW)
Select Case OP
Case ERROR_OP.MAIL
sendERRORperMail(title & " | " & My.Application.Info.AssemblyName, message, stack, mailadess, zusatz, functionName)
Case ERROR_OP.SHOW
'MsgBox("Fehler in der Funktion '" & System.Reflection.MethodInfo.GetCurrentMethod.Name & "'" & vbNewLine & vbNewLine & ex.Message)
MsgBox(If(functionName <> "", "Fehler in der Funktion '" & functionName & "'" & vbNewLine & vbNewLine, "") & message & vbNewLine & stack & vbNewLine & zusatz, MsgBoxStyle.OkOnly, If(title <> "", title, "Fehler"))
End Select
VERAG_PROG_ALLGEMEIN.cERS.saveErr(OP, message, stack, errCode, functionName, recieverMailAdress, zusatz)
End Sub
Public Shared Sub sendERRORperMail(title, errmsg, errstack, recieverMailAdress, zusatz, functionName)
Dim Msg As New MailMessage
Dim myCredentials As New System.Net.NetworkCredential
'myCredentials.UserName = "support@verag.ag"
'myCredentials.Password = "$up0Rt2809!"
myCredentials.UserName = "al@verag.ag"
myCredentials.Password = "verag#2"
Msg.IsBodyHtml = False
Dim mySmtpsvr As New SmtpClient()
mySmtpsvr.Host = "owa.verag.ag" 'bei web.de
mySmtpsvr.Port = 25 '587 '25
mySmtpsvr.UseDefaultCredentials = False
mySmtpsvr.Credentials = myCredentials
Try
Msg.From = New MailAddress("al@verag.ag")
Msg.To.Add(recieverMailAdress)
Msg.Subject = title '"ERROR - DAKOSY Einarbeitung"
Msg.Body = "Uhrzeit: " & Now.ToShortDateString & " " & Now.ToShortTimeString
Msg.Body = "Function: " & functionName
Msg.Body &= vbNewLine
Msg.Body &= vbNewLine
Msg.Body &= "Fehlermeldung: " & errmsg
Msg.Body &= vbNewLine
Msg.Body &= vbNewLine
Msg.Body &= "Stacktrace: " & errstack
Msg.Body &= vbNewLine
If zusatz <> "" Then
Msg.Body &= "Zusatz: " & zusatz
Msg.Body &= vbNewLine
End If
Msg.Body &= errstack
mySmtpsvr.Send(Msg)
Catch ex As Exception
Try
mySmtpsvr.Host = "192.168.0.107" 'bei web.de ' 235
mySmtpsvr.Send(Msg)
Catch ex2 As Exception
' MsgBox(ex.Message & ex.StackTrace)
End Try
End Try
End Sub
End Class
Public Class ERROR_OP
Shared Property SHOW As String = "SHOW"
Shared Property MAIL As String = "MAIL"
Shared Property TOFILE As String = "TOFILE"
Shared Property LOG As String = "LOG" 'Nur fürs Protokoll, keine Fehlermeldung
End Class