[vb.net] 오류 로그확인 및 오류 메시지 저장 > vb.net

본문 바로가기

vb.net

[기타] [vb.net] 오류 로그확인 및 오류 메시지 저장

회원사진
하나를하더라도최선을
2019-09-19 20:42 8,206 0
  • - 첨부파일 : ErrorsAndEvents.dll (12.0K) - 다운로드

본문



        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 StringByVal stkTrace As StringByVal 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
 
 

댓글목록0

등록된 댓글이 없습니다.
게시판 전체검색