We help IT Professionals succeed at work.
Get Started

Logging Exceptions Visual Basic

GIANTOCR
GIANTOCR asked
on
334 Views
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?

Thanks.
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 " & _
                My.Computer.Clock.GmtTime.ToString)
            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" ?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="BoilerReadings.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <connectionStrings>
        <add name="BoilerReadings.My.MySettings.FacOpsDataConnectionString"
            connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\FacOpsData.mdb"
            providerName="System.Data.OleDb" />
    </connectionStrings>
    <system.diagnostics>
        <sources>
            <!-- This section defines the logging configuration for My.Application.Log -->
            <source name="DefaultSource" switchName="DefaultSwitch">
                <listeners>
                    <add name="FileLog"/>
                    <!-- Uncomment the below section to write to the Application Event Log -->
                    <!--<add name="EventLog"/>-->
                </listeners>
            </source>
        </sources>
        <switches>
            <add name="DefaultSwitch" value="Information" />
        </switches>
        <sharedListeners>
            <add name="FileLog"
                 type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
                 initializeData="FileLogWriter"/>
            <!-- 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"/> -->
        </sharedListeners>
    </system.diagnostics>
    <applicationSettings>
        <BoilerReadings.My.MySettings>
            <setting name="oledbConnectionString" serializeAs="String">
                <value>Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\FacOpsData.mdb</value>
            </setting>
        </BoilerReadings.My.MySettings>
    </applicationSettings>
</configuration>

Open in new window

Comment
Watch Question
Top Expert 2009
Commented:
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