ComponentSpace Professional .NET and ActiveX components for developers
ComponentSpace Home | Products | Downloads | Support | Purchase | Services | About Us
 

Code Samples

The product includes numerous Visual Basic sample applications. All samples include complete source code. For more detailed sample code please refer to the sample applications.


Writing Event Log Entries

Listing 1 demonstrates writing event log entries. Information, warning and error entries may be written. Events will be written to the event log under which the event source is configured. This can be the application, system or some custom event log. Insertion strings and binary data may optionally be included with the event.



Private Sub WriteEvents()
    ' Setup the event source
    Dim EventSource As New EventSource
    
    EventSource.SourceName = "mysource"
    
    ' Report the event - no strings or binary data
    EventSource.ReportInformation "my event"
    
    ' Report the event - one string
    EventSource.ReportWarning "my event", "This is a single string"
    
    ' Report the event - multiple strings
    EventSource.ReportError "my event", _
        Array("This", "is", "an", "array", "of", "strings")
    
    ' Report the event - binary data
    EventSource.ReportInformation "my event", , _
        Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)
    
    ' Report the event - strings and binary data
    EventSource.ReportWarning "my event", _
        Array("This", "is", "an", "array", "of", "strings"), _
        Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)
End Sub
									

Listing 1 Writing event log entries


Reading Event Logs

Listing 2 demonstrates enumerating event log records in an event log.



Private Sub EnumerateLogEntries()
    ' Enumerate the application log
    Dim EventLog As New EventLog
    Dim EventLogRecord As EventLogRecord
    
    For Each EventLogRecord In EventLog.EventLogRecords
        ' Process each event log record
        Dim Text As String

        Text = EventLogRecord.SourceName
        Text = EventLogRecord.EventDescription
    Next
End Sub
									

Listing 2 Reading event logs


Saving Event Logs

Listing 3 demonstrates saving an event log to a file.



Private Sub SaveEventLog()
    ' Back the event log to file
    Dim EventLog As New EventLog
        
    EventLog.ComputerName = "myserver"
    EventLog.SourceName = "application"
        
    EventLog.Backup "application.evt"
End Sub
									

Listing 3 Saving event logs