VB.Net Tutorial/Windows/EventLog

Материал из VB Эксперт
Версия от 12:56, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Display all Application EventLog

Imports System.Diagnostics
Module Module1
    Sub Main()
        Dim Log As New EventLog("Application")
        Dim Evt As EventLogEntry
        For Each Evt In Log.Entries
            Console.WriteLine(Evt.Message)
            Console.WriteLine(Evt.TimeGenerated)
            
            Console.WriteLine(Evt.Source)
            
        Next
    End Sub
End Module
The description for Event ID "0" in Source "CacheMgr" cannot be found.  The local computer may not h
ave the necessary registry information or message DLL files to display the message, or you may not h
ave permission to access them.  The following information is part of the event:"Service started"
15/04/2007 12:41:55 PM
CacheMgr
The description for Event ID "1073872930" in Source "Oracle.xe" cannot be found.  The local computer
...

EventLogEntryType.Information

Imports System.Diagnostics
public class Test
   Shared Dim logStatus As System.Diagnostics.EventLog = New System.Diagnostics.EventLog
   public Shared Sub Main
        
        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.
        ShowLog()
        logStatus.Clear()
        ShowLog()
   End Sub
    Private Shared Sub ShowLog()
        For Each log_entry As EventLogEntry In logStatus.Entries
            Console.WriteLine(log_entry.Message)
        Next log_entry
    End Sub
   
End class
11/05/2007 12:29:16 PM> Starting
11/05/2007 12:29:16 PM> Closing

Write to System EventLog

Imports System.Diagnostics
Module Module1
    Sub Main()
        Dim Log As New EventLog("Application")
        Log.Source = "FormEventLog"
        Log.WriteEntry("www.vbex.ru")
    End Sub
End Module