We help IT Professionals succeed at work.
Get Started

Logging Exceptions Visual Basic

Last Modified: 2012-05-06
I made a Windows application using Visual Basic 2005. I would like to write Unhandled Exceptions to the application log. Below is the code I am using to do this. I have also included the code from the app.config file.

I have deployed the application on another computer and encountered some exceptions that caused the application to shutdown. I am trying to find the application log, but am unable to find it. How can I locate the application log on the computer?

Partial Friend Class MyApplication
        Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException
            'Exception logging code copied from "How to: Log Exceptions in Visual Basic "
            My.Application.Log.WriteException(e.Exception, _
                TraceEventType.Critical, _
                "Application shut down at " & _
            MessageBox.Show("An unexpected error has occurred. The application will shut down.")
            'It is the default that the application closes after this event has occured
        End Sub
    End Class
<?xml version="1.0" encoding="utf-8" ?>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="BoilerReadings.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        <add name="BoilerReadings.My.MySettings.FacOpsDataConnectionString"
            connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\FacOpsData.mdb"
            providerName="System.Data.OleDb" />
            <!-- This section defines the logging configuration for My.Application.Log -->
            <source name="DefaultSource" switchName="DefaultSwitch">
                    <add name="FileLog"/>
                    <!-- Uncomment the below section to write to the Application Event Log -->
                    <!--<add name="EventLog"/>-->
            <add name="DefaultSwitch" value="Information" />
            <add name="FileLog"
                 type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
            <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
            <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
            <setting name="oledbConnectionString" serializeAs="String">
                <value>Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\FacOpsData.mdb</value>

Open in new window

Watch Question
Top Expert 2009
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE