How to: Write to an Application Event Log (Visual Basic)
You can use the My.Application.Log and My.Log objects to write information about events that occur in your application. This example shows how to configure an event log listener so My.Application.Log writes tracing information to the Application event log.
You cannot write to the Security log. In order to write to the System log, you must be a member of the LocalSystem or Administrator account.
To view an event log, you can use Server Explorer or Windows Event Viewer. For more information, see ETW Events in the .NET Framework.
Event logs are not supported on Windows 95, Windows 98, or Windows Millennium Edition.
To add and configure the event log listener
Right-click app.config in Solution Explorer and choose Open.
- or -
If there is no app.config file,
On the Project menu, choose Add New Item.
From the Add New Item dialog box, choose Application Configuration File.
Locate the <listeners> section in the application configuration file.
You will find the <listeners> section in the <source> section with the name attribute "DefaultSource", which is nested under the <system.diagnostics> section, which is nested under the top-level <configuration> section.
Add this element to that <listeners> section:
Locate the <sharedListeners> section, in the <system.diagnostics> section, in the top-level <configuration> section.
Add this element to that <sharedListeners> section:
<add name="EventLog" type="System.Diagnostics.EventLogTraceListener, System, Version=188.8.131.52, Culture=neutral, PublicKeyToken=b77a5c561934e089" initializeData="APPLICATION_NAME"/>
Replace APPLICATION_NAME with the name of your application.
Typically, an application writes only errors to the event log. For information on filtering log output, see Walkthrough: Filtering My.Application.Log Output (Visual Basic).
To write event information to the event log
Use the My.Application.Log.WriteEntry or My.Application.Log.WriteException method to write information to the event log. For more information, see How to: Write Log Messages (Visual Basic) and How to: Log Exceptions in Visual Basic.
After you configure the event log listener for an assembly, it receives all messages that My.Applcation.Log writes from that assembly.