本文整理匯總了VB.NET中System.Diagnostics.EventLog.EventLog構造函數的典型用法代碼示例。如果您正苦於以下問題:VB.NET EventLog構造函數的具體用法?VB.NET EventLog怎麽用?VB.NET EventLog使用的例子?那麽, 這裏精選的構造函數代碼示例或許可以為您提供幫助。您也可以進一步了解該構造函數所在類System.Diagnostics.EventLog
的用法示例。
在下文中一共展示了EventLog構造函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: MySample
Option Explicit
Option Strict
Imports System.Diagnostics
Imports System.Threading
Class MySample
Public Shared Sub Main()
If Not EventLog.SourceExists("MySource") Then
' Create the source, if it does not already exist.
' An event log source should not be created and immediately used.
' There is a latency time to enable the source, it should be created
' prior to executing the application that uses the source.
' Execute this sample a second time to use the new source.
EventLog.CreateEventSource("MySource", "MyNewLog")
Console.WriteLine("CreatingEventSource")
'The source is created. Exit the application to allow it to be registered.
Return
End If
' Create an EventLog instance and assign its source.
Dim myLog As New EventLog()
myLog.Source = "MySource"
' Write an informational entry to the event log.
myLog.WriteEntry("Writing to event log.")
End Sub
End Class
示例2: MySample
Option Explicit
Option Strict
Imports System.Diagnostics
Imports System.Threading
Class MySample
Public Shared Sub Main()
If Not EventLog.SourceExists("MySource") Then
' Create the source, if it does not already exist.
' An event log source should not be created and immediately used.
' There is a latency time to enable the source, it should be created
' prior to executing the application that uses the source.
' Execute this sample a second time to use the new source.
EventLog.CreateEventSource("MySource", "MyNewLog")
Console.WriteLine("CreatingEventSource")
'The source is created. Exit the application to allow it to be registered.
Return
End If
Dim myLog As New EventLog("myNewLog")
' Read the event log entries.
Dim entry As EventLogEntry
For Each entry In myLog.Entries
Console.WriteLine((ControlChars.Tab & "Entry: " & entry.Message))
Next entry
End Sub
End Class
示例3: MySample
Option Explicit
Option Strict
Imports System.Diagnostics
Imports System.Threading
Class MySample
Public Shared Sub Main()
If Not EventLog.SourceExists("MySource") Then
' Create the source, if it does not already exist.
' An event log source should not be created and immediately used.
' There is a latency time to enable the source, it should be created
' prior to executing the application that uses the source.
' Execute this sample a second time to use the new source.
EventLog.CreateEventSource("MySource", "MyNewLog", "myServer")
Console.WriteLine("CreatingEventSource")
'The source is created. Exit the application to allow it to be registered.
Return
End If
' Create an EventLog instance and assign its log name.
Dim myLog As New EventLog("myNewLog", "myServer")
' Read the event log entries.
Dim entry As EventLogEntry
For Each entry In myLog.Entries
Console.WriteLine((ControlChars.Tab & "Entry: " & entry.Message))
Next entry
End Sub
End Class
示例4: MySample
Option Strict
Option Explicit
Imports System.Diagnostics
Imports System.Threading
Class MySample
Public Shared Sub Main()
If Not EventLog.SourceExists("MySource") Then
' Create the source, if it does not already exist.
' An event log source should not be created and immediately used.
' There is a latency time to enable the source, it should be created
' prior to executing the application that uses the source.
' Execute this sample a second time to use the new source.
EventLog.CreateEventSource("MySource", "MyNewLog")
Console.WriteLine("CreatingEventSource")
'The source is created. Exit the application to allow it to be registered.
Return
End If
' Create an EventLog instance and assign its source.
Dim myLog As New EventLog("myNewLog", ".", "MySource")
' Write an entry to the log.
myLog.WriteEntry(("Writing to event log on " & myLog.MachineName))
End Sub
End Class