Dit artikel is gepubliceerd op zondag 31 juli 2011 op vbvoorbeelden, bezoek de website voor een recente versie van dit artikel of andere artikels.
Visual Basic 2010 Broncode
Namespace My Partial Friend Class MyApplication Private Sub MyApplication_Startup()
Handles Me.Startup
My.Application.Log.WriteEntry(
"Starting Application at " & _
Date.Now.ToString())
End Sub Private Sub MyApplication_Shutdown()
Handles Me.Shutdown
My.Application.Log.WriteEntry(
"Closing Application at " & _
Date.Now.ToString())
End Sub End ClassEnd NamespaceVoeg een Application Configuration File ( app.config ) toe aan het project en vervang de configuratie door :
Application Configuration File
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<sources>
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog"/>
</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"
location="ExecutableDirectory"/>
</sharedListeners>
</system.diagnostics>
</configuration>Voer de applicatie uit en sluit deze. Bekijk nu het gecreëerde logbestand. Deze bevindt zich door bovenstaande configuratie in dezelfde directory als de executable van de assembly, en zal ook dezelfde naam hebben als de assembly.
Het logbestand bevat volgende boodschappen :
Tekst Bestand
DefaultSource Information 0 Starting Application at 25/10/2008 10:07:26
DefaultSource Information 0 Closing Application at 25/10/2008 10:07:32'
Dit artikel is gepubliceerd op zondag 31 juli 2011 op vbvoorbeelden, bezoek de website voor een recente versie van dit artikel of andere artikels.