WriteEntry 方法(My.Application.Log 和 My.Log)

更新:2007 年 11 月

将一条消息写入应用程序的日志侦听器。

' Usage
My.Application.Log.WriteEntry(message)
My.Application.Log.WriteEntry(message ,severity)
My.Application.Log.WriteEntry(message ,severity ,id)
' Web usage
My.Log.WriteEntry(message)
My.Log.WriteEntry(message ,severity)
My.Log.WriteEntry(message ,severity ,id)
' Declaration
Public Sub WriteEntry( _
   ByVal message As String _
)
' -or-
Public Sub WriteEntry( _
   ByVal message As String, _
   ByVal severity As System.Diagnostics.TraceEventType _
)
' -or-
Public Sub WriteEntry( _
   ByVal message As String, _
   ByVal severity As System.Diagnostics.TraceEventType, _
   ByVal id As Integer _
)

参数

  • message
    必选。要记录的消息。如果 message 为 Nothing,则使用空字符串。

  • severity
    消息的类型。默认情况下为 TraceEventType.Information。

  • id
    消息标识符,通常用于建立关联。默认情况下与 entryType 相关,如表中所述。

异常

下面的情况会导致异常:

备注

WriteEntry 方法将消息写入应用程序的事件日志侦听器。

在客户端应用程序中,Log 对象是通过 My.Application.Log 对象提供的。在 Web 应用程序中,Log 对象是通过 My.Log 对象提供的。

若要了解哪些日志侦听器接收 WriteEntry 方法的消息,请参见演练:确定 My.Application.Log 写入信息的位置。可以更改默认日志侦听器。有关更多信息,请参见使用 Application 日志 (Visual Basic)

对于不接受 id 参数的重载,写入日志的 id 是由下表定义的。

severity

默认 id

Information

0

Warning

1

Error

2

Critical

3

Start

4

Stop

5

Suspend

6

Resume

7

Verbose

8

Transfer

9

任务

下表列出了涉及 WriteEntry 方法的任务的示例。

要执行的操作

请参见

将事件信息写入应用程序的日志侦听器

如何:写入日志消息

确定 Log 在何处写入信息

演练:确定 My.Application.Log 写入信息的位置

示例

此示例说明如何使用 My.Application.Log.WriteEntry 方法来记录跟踪信息。有关更多信息,请参见如何:写入日志消息

Public Sub TracingTest(ByVal fileName As String)
    My.Application.Log.WriteEntry( _
        "Entering TracingTest with argument " & _
        fileName & ".")
    ' Code to trace goes here.
    My.Application.Log.WriteEntry( _
        "Exiting TracingTest with argument " & _
        fileName & ".")
End Sub

此代码示例只能在客户端应用程序内运行。对于 Web 应用程序,请将 My.Application.Log.WriteEntry 改为 My.Log.WriteEntry。

要求

命名空间:Microsoft.VisualBasic.Logging

类:Log

**程序集:**Visual Basic 运行库(在 Microsoft.VisualBasic.dll 中)

按项目类型列出的可用性

项目类型

可用

Windows 应用程序

类库

控制台应用程序

Windows 控件库

Web 控件库

Windows 服务

网站

权限

以下权限可能是必需的:

权限

说明

FileIOPermission

控制访问文件和文件夹的能力。关联的枚举:Unrestricted

有关更多信息,请参见代码访问安全性请求权限

请参见

任务

如何:写入日志消息

演练:确定 My.Application.Log 写入信息的位置

概念

使用 Application 日志 (Visual Basic)

参考

My.Application.Log 对象

My.Log 对象

System.Diagnostics.TraceEventType

Log.WriteEntry