| 网站首页 | VB.Net实例分析 | .Net技术文摘 | 下载中心 | VB.Net书籍笔记 | .Net源码 | VBS脚本与组件调用 | Windows2008技术文摘 | 给我们留言 | 
最新公告:

  没有公告

您现在的位置: 乐博网 >> VB.Net实例分析 >> 实例学习笔记 >> 实例分析正文
最新推荐 更多内容
读取事件日志(VB2010实例)
读取事件日志(VB2010实例)
作者:Akyao    来源:乐博网收集     更新时间:2011-4-4

读取事件日志(VB2010实例)

VB2010源码如下:

 

' Copyright (c) Microsoft Corporation. All rights reserved.
Public Class ReadForm
    ' Stores the name of the log that the user wants to view.
    Private logType As String = ""

    Private Sub cmdViewLogEntries_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnViewLogEntries.Click
        Try
            Const EntriesToDisplay As Integer = 10   '更多.net源代码和教程 来自乐博网 lob.cn

            ' In this case the EventLog constructor is passed a string variable for the log name.
            ' This is because the user of the application can choose which log they wish to view
            ' from the listbox on the form.
            Dim ev As New EventLog(logType, System.Environment.MachineName, _
                "Event Log Sample")

            rchEventLogOutput.Text = "Event log entries (maximum of 10), newest to oldest." & vbCrLf & vbCrLf

            Dim lastLogToShow As Integer = ev.Entries.Count - EntriesToDisplay
            If lastLogToShow < 0 Then
                lastLogToShow = 0
            End If

            ' Display the last 10 records in the chosen log.
            For index As Integer = ev.Entries.Count - 1 To lastLogToShow Step -1
                Dim CurrentEntry As EventLogEntry = ev.Entries(index)
                rchEventLogOutput.Text &= "Event ID : " & CurrentEntry.InstanceId & vbCrLf
                rchEventLogOutput.Text &= "Entry Type : " & _
                    CurrentEntry.EntryType.ToString() & vbCrLf
                rchEventLogOutput.Text &= "Message : " & _
                    CurrentEntry.Message & vbCrLf & vbCrLf
            Next
        Catch secEx As System.Security.SecurityException
            MsgBox("Security exception in reading the event log.", MsgBoxStyle.OKOnly, Me.Text & " Error")
        Catch ex As Exception
            MsgBox("Error accessing logs on the local machine.", MsgBoxStyle.OKOnly, Me.Text & " Error")
        End Try
    End Sub

    Private Sub lstEntryType_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstEntryType.SelectedIndexChanged
        ' Store the log that the user selected in the ListBox
        logType = CType(lstEntryType.Items(lstEntryType.SelectedIndex()), String)
    End Sub

    Private Sub ReadForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            For Each currentLog As EventLog In EventLog.GetEventLogs()
                lstEntryType.Items.Add(currentLog.LogDisplayName)
            Next
            lstEntryType.SelectedIndex = 0
        Catch secEx As System.Security.SecurityException
            MsgBox("Security exception in reading the event log.", MsgBoxStyle.OKOnly, Me.Text & " Error")
        Catch ex As Exception
            MsgBox("Error accessing logs on the local machine.", MsgBoxStyle.OKOnly, Me.Text & " Error")
        End Try
    End Sub

    Private Sub CloseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem.Click
        Me.Close()
    End Sub

End Class

  • 上一篇:

  • 下一篇:
  • 【字体: 】【打印此文】【关闭窗口
      相关文章:(只显示最新16条)
    显示进程组成模块(VB2010实例)
    任务管理器编程(VB2010实例)
    性能计数器编程(VB2010实例)
    消息队列MSMQListener(VB2010实例)
    消息队列MSMQClient(VB2010实例)
    写入事件日志(VB2010实例)
    创建和删除事件日志(VB2010实例)
    COMPort编程(VB2010实例)
    读取大文件(VB2010实例)
    读取文件(VB2010实例)
    文件移动(VB2010实例)
    获取驱动器磁盘信息(VB2010实例)
    目录搜索和目录查找(VB2010实例)
    文件搜索和文件查找(VB2010实例)
    选择文件目录(VB2010实例)
    删除文件(VB2010实例)

    | 设为首页 | 加入收藏 | 联系站长 | | 友情链接 | 版权申明 |
    乐博网欢迎各种媒体转载我们的原创作品[转载请注明出处];我们鼓励更多VB.Net开发者一起加入研究与探讨;如发现文章访问错误、内容错误或版权疑问、内容有违相关法律(如涉及政治、色情、反动或散布虚假有害信息)等情况,请及时向我们举报,我们将及时纠正!
    联系邮箱:Shiny#vip.qq.com (#替换为@) QQ交流群: 40797788 [闽ICP备05014267号]