728x90
블로그 인기글
● 메이플스토리 신규 룬패치/자동해제 프로그램 [링크 이동]
● 메이플스토리 거짓말탐지기 알림 프로그램 [링크 이동]
● C#에서 TensorFlow 사용하는법 [링크 이동]
Public el As New ErrorsAndEvents.ErrorLogger
Try
'// 여기에 프로그래밍
Catch ex As Exception
LOG(ex.StackTrace) '// 프로그램에서 로그기록 함수
el.WriteToErrorLog(ex.Message, ex.StackTrace, "GetAPI") '// 오류 로그 기록
End Try
Imports System.IO
Imports System.Text
Imports System.Windows.Forms
<CLSCompliant(True)> _
Public Class ErrorLogger
Public Sub New()
'default constructor
End Sub
'*************************************************************
'NAME: WriteToErrorLog
'PURPOSE: Open or create an error log and submit error message
'PARAMETERS: msg - message to be written to error file
' stkTrace - stack trace from error message
' title - title of the error file entry
'RETURNS: Nothing
'*************************************************************
Public Sub WriteToErrorLog(ByVal msg As String, ByVal stkTrace As String, ByVal title As String)
'check and make the directory if necessary; this is set to look in the application
'folder, you may wish to place the error log in another location depending upon the
'the user's role and write access to different areas of the file system
If Not System.IO.Directory.Exists(Application.StartupPath & "\Errors\") Then
System.IO.Directory.CreateDirectory(Application.StartupPath & "\Errors\")
End If
'check the file
Try
Using fs As FileStream = New FileStream(Application.StartupPath & "\Errors\errlog.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite)
Dim s As StreamWriter = New StreamWriter(fs)
s.Close()
fs.Close()
End Using
Catch ex As Exception
End Try
'log it
Try
Using fs1 As FileStream = New FileStream(Application.StartupPath & "\Errors\errlog.txt", FileMode.Append, FileAccess.Write)
Dim s1 As StreamWriter = New StreamWriter(fs1)
s1.Write("Title: " & title & vbCrLf)
s1.Write("Message: " & msg & vbCrLf)
s1.Write("StackTrace: " & stkTrace & vbCrLf)
s1.Write("Date/Time: " & DateTime.Now.ToString() & vbCrLf)
s1.Write("===========================================================================================" & vbCrLf)
s1.Close()
fs1.Close()
End Using
Catch ex As Exception
End Try
End Sub
End Class
728x90
'자료' 카테고리의 다른 글
[C#/vb.net] 수학 함수 (0) | 2020.08.17 |
---|---|
[C#/vb.net] HTML 정리 및 테그 제거 (0) | 2020.08.17 |
[C#/vb.net] Selenium WebDriver 파일(이미지, 동영상) 업로드 및 내용 붙여넣기 샘플 (0) | 2020.08.16 |
[C#/vb.net] vb.net 에서 동적 컨트롤에 익명매소드를 이용해서 이벤트 걸기 (0) | 2020.08.16 |
[C#/vb.net] Visual Basic에서 예외 기록 / LOG 기록 (0) | 2020.08.16 |