一般性的错误日至处理,可以记录到系统得日至管理
日志类型:
Imports System.Diagnostics
![](/Images/OutliningIndicators/None.gif)
' Windows 事件日志记录
Public Class EventLogHelper
![](/Images/OutliningIndicators/None.gif)
Private Shared ReadOnly m_eventLogSource As String = "IssueVision Smart Client 1.0"
![](/Images/OutliningIndicators/None.gif)
' 因为是一个静态类,所以阻止被实例化,最好的方法就是用private 修饰构造函数
Private Sub New()
End Sub
![](/Images/OutliningIndicators/None.gif)
' 检查是否已经存在日志源名称
Public Shared Function Exists(ByVal eventSourceName As String) As Boolean
Return EventLog.Exists(eventSourceName)
End Function
![](/Images/OutliningIndicators/None.gif)
' 创建一个日志源
Public Shared Sub CreateSource(ByVal eventSourceName As String)
If (EventLog.Exists(eventSourceName) = False) Then
EventLog.CreateEventSource(eventSourceName, "Application")
End If
End Sub
![](/Images/OutliningIndicators/None.gif)
' 移除日志源
Public Shared Sub RemoveSource(ByVal eventSourceName As String)
If (EventLog.Exists(eventSourceName)) Then
EventLog.DeleteEventSource(eventSourceName, "Application")
End If
End Sub
![](/Images/OutliningIndicators/None.gif)
' 添加一个错误日志.
Public Shared Sub LogError(ByVal message As String)
LogEvent(m_eventLogSource, message, EventLogEntryType.Error)
End Sub
![](/Images/OutliningIndicators/None.gif)
' 添加一个失败日志
Public Shared Sub LogFailureAudit(ByVal message As String)
LogEvent(m_eventLogSource, message, EventLogEntryType.FailureAudit)
End Sub
![](/Images/OutliningIndicators/None.gif)
' 添加一个成功日志.
Public Shared Sub LogSuccessAudit(ByVal message As String)
LogEvent(m_eventLogSource, message, EventLogEntryType.SuccessAudit)
End Sub
![](/Images/OutliningIndicators/None.gif)
' 添加一个警告日志
Public Shared Sub LogWarning(ByVal message As String)
LogEvent(m_eventLogSource, message, EventLogEntryType.Warning)
End Sub
![](/Images/OutliningIndicators/None.gif)
' 记录一个消息到应用程序日志.
Public Shared Sub LogInformation(ByVal message As String)
LogEvent(m_eventLogSource, message, EventLogEntryType.Information)
End Sub
![](/Images/OutliningIndicators/None.gif)
' 记录一个特殊类型的消息到应用程序日志
Private Shared Sub LogEvent(ByVal eventLogSource As String, ByVal message As String, ByVal eventLogEntryType As EventLogEntryType)
EventLog.WriteEntry(eventLogSource, message, eventLogEntryType)
End Sub
![](/Images/OutliningIndicators/None.gif)
End Class
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)