기타 [vb.net] 오류 로그확인 및 오류 메시지 저장
페이지 정보
본문
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
첨부파일
-
ErrorsAndEvents.dll (12.0K)
6회 다운로드 | DATE : 2019-09-19 20:43:24
- 이전글[vb.net] 텍스트파일(CSV) 파싱 19.09.19
- 다음글[vb.net] 코드가 실행 상태 즉 디버그 모드인지 아닌지에 따라서 실행되게 하기 19.09.19
댓글목록
등록된 댓글이 없습니다.