| 网站首页 | 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 WriteForm

    Private entryType As System.Diagnostics.EventLogEntryType = EventLogEntryType.Information

    Private Sub cmdWriteEntry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
        Handles btnWriteEntry.Click

        Try
            If IsNumeric(txtEventID.Text) Then
                ' The first entry is the name of the log you want to write to.  The second
                ' parameter is the machine name.  In this case it is the local machine name.
                ' The third parameter is the source of the event.  Commonly this is set equal
                ' to the name of the application that is writing the event.
                Dim ev As New EventLog("Application", My.Computer.Name, "Event Log Sample")

                ' The first argument to WriteEntry is the text of the message.  The second
                ' argument is the type of entry you want to create (Warning, Information, etc.)
                ' The third is the eventID of the event.  The user could use this to look up
                ' further information in a help file.
                ev.WriteEntry(txtEntry.Text, entryType, CInt(txtEventID.Text))

                ev.Close()

                MsgBox("Entry written to the event log", MsgBoxStyle.OKOnly, Me.Text)
            Else
                ' The EventID was not numeric
                MsgBox("Value entered into EventID text box must be numeric.", MsgBoxStyle.OKOnly, _
                    Me.Text & " Error")
            End If
        Catch secEx As System.Security.SecurityException
            MsgBox("Security error writing to 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 rdo_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
        Handles rdoError.Click, rdoInfo.Click, rdoWarning.Click

        ' This event procedure handles the click event for all the radio buttons in
        ' the group box on the form.  In the event handler, we know which radio
        ' button was clicked because it is passed in as the "sender" argument.
        ' This comes in as a generic object, however, and must be cast back to a
        ' radio button so that you can access the name property.

        Dim rdo As RadioButton = CType(sender, RadioButton)
        Select Case rdo.Name
            Case "rdoError"
                entryType = EventLogEntryType.Error
            Case "rdoWarning"
                entryType = EventLogEntryType.Warning
            Case "rdoInfo"
                entryType = EventLogEntryType.Information
            Case Else
                MsgBox("Select an entry type.")
        End Select

    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实例)
    COMPort编程(VB2010实例)
    读取大文件(VB2010实例)
    读取文件(VB2010实例)
    文件移动(VB2010实例)
    获取驱动器磁盘信息(VB2010实例)
    目录搜索和目录查找(VB2010实例)
    文件搜索和文件查找(VB2010实例)
    选择文件目录(VB2010实例)
    删除文件(VB2010实例)
    复制文件(VB2010实例)
    复制目录(VB2010实例)
    DateTime(VB2010实例)
    arrays(VB2010实例)
    APICalls(VB2010实例)

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