[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 525
  • Last Modified:

vb.net 2008 error log file

how can i create and write error log file in vb.net 2008?
Pls provide some code
0
aarontham
Asked:
aarontham
1 Solution
 
DhaestCommented:
0
 
VBRocksCommented:
Here's how you can do it:

    Public Sub WriteError(ByVal e As Exception)

        'Set this to the name of your application
        Dim AppName As String = "My application"

        'Set this to the name of the Log (like "Application" log)
        Dim LogName As String = "MyLog"

        Dim log As New EventLog()

        If Not EventLog.SourceExists(AppName) Then _
            EventLog.CreateEventSource(AppName, LogName)

        log.Source = AppName

        Dim msg As String = "The following unhandled exception has occurred in the " & _
            AppName & " application:" & vbCrLf & vbCrLf & _
            e.Message

        'Write the error to the EventLog
        log.WriteEntry(msg, System.Diagnostics.EventLogEntryType.Error)

    End Sub



Write an error like this:

        Dim errMessage As String = "write this error"

        WriteError(New Exception(errMessage))

        MsgBox("done")


You can view the entry in your log:

    Open Windows Administrative Tools | Event Viewer

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now