VB.Net/Windows System/Event Log
Event Log
<source lang="vbnet"> Public Class MainClass
Public Shared Function WriteToEventLog(ByVal Entry As String, _ Optional ByVal AppName As String = "AAA", Optional ByVal EventType As EventLogEntryType = EventLogEntryType.Information, Optional ByVal LogName As String = "Application") As Boolean Dim objEventLog As New EventLog() Try If Not EventLog.SourceExists(AppName) Then EventLog.CreateEventSource(AppName, LogName) End If objEventLog.Source = AppName objEventLog.WriteEntry(Entry, EventType) Return True Catch Ex As Exception Return False End Try End Function Public Shared Sub Main() WriteToEventLog("11111") WriteToEventLog("message", "Authenticator", EventLogEntryType.Error, "Special Log") End Sub
End Class
</source>
Event Log: create event source and display
<source lang="vbnet"> Imports System Imports System.Data Imports System.Windows.Forms Imports System.Drawing Imports System.Diagnostics Public Class MainClass
Shared Sub Main() Dim logStatus As System.Diagnostics.EventLog logStatus = New System.Diagnostics.EventLog If Not EventLog.SourceExists("StatusSource") Then EventLog.CreateEventSource("StatusSource", "StatusLog") Console.WriteLine("Creating event source") End If " Set the EventLog component"s source. logStatus.Source = "StatusSource" " Write a Starting message to the log. logStatus.WriteEntry(Now & "> " & "Starting", _ EventLogEntryType.Information)
For Each log_entry As EventLogEntry In logStatus.Entries Console.WriteLine(log_entry.Message) Next log_entry End Sub
End Class
</source>