Solved 2008 error log file

Posted on 2009-02-23
Last Modified: 2013-11-25
how can i create and write error log file in 2008?
Pls provide some code
Question by:aarontham
    LVL 27

    Expert Comment

    LVL 53

    Accepted Solution

    LVL 27

    Expert Comment

    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 & _

            '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))


    You can view the entry in your log:

        Open Windows Administrative Tools | Event Viewer


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now