Avatar of GIANTOCR
GIANTOCR

asked on 

Logging Exceptions Visual Basic

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

Visual Basic.NET

Avatar of undefined
Last Comment
abel

8/22/2022 - Mon