Log.WriteEntry 方法  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将消息写入应用程序的日志侦听器中。
重载
| WriteEntry(String) | 将消息写入应用程序的日志侦听器中。 | 
| WriteEntry(String, TraceEventType) | 将消息写入应用程序的日志侦听器中。 | 
| WriteEntry(String, TraceEventType, Int32) | 将消息写入应用程序的日志侦听器中。 | 
WriteEntry(String)
将消息写入应用程序的日志侦听器中。
public:
 void WriteEntry(System::String ^ message);public void WriteEntry (string message);member this.WriteEntry : string -> unitPublic Sub WriteEntry (message As String)参数
- message
- String
必需。 要记录的消息。 如果 message 为 Nothing,则返回一个空字符串。
例外
具有部分信任的代码调用该方法,但是写入到需要完全信任的事件日志侦听器。
示例
本示例将演示如何使用 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.Log.WriteEntry更改为 My.Application.Log.WriteEntry 。
注解
方法 WriteEntry 将消息写入应用程序的事件日志侦听器。
在客户端应用程序中 Log ,对象通过 My.Application.Log 对象可用。 在 Web 应用程序中, Log 对象通过 My.Log 对象可用。
若要了解哪些日志侦听器接收 WriteEntry 方法的消息,请参阅 演练:确定 My.Application.Log 写入信息的位置。 可以更改默认日志侦听器。 有关详细信息,请参阅使用应用程序日志。
对于不采用 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 在哪里写入信息 | 
可用性(按项目类型)
| 项目类型 | 可用 | 
|---|---|
| Windows 应用程序 | 是 | 
| 类库 | 是 | 
| 控制台应用程序 | 是 | 
| Windows 控件库 | 是 | 
| Web 控件库 | 否 | 
| Windows 服务 | 是 | 
| 网站 | 是 | 
另请参阅
- TraceEventType
- 对象 (Visual Basic)
- 使用 Application 日志 (Visual Basic)
- 如何:写入日志消息
- 演练:确定 My.Application.Log 写入信息的位置
适用于
WriteEntry(String, TraceEventType)
将消息写入应用程序的日志侦听器中。
public:
 void WriteEntry(System::String ^ message, System::Diagnostics::TraceEventType severity);public void WriteEntry (string message, System.Diagnostics.TraceEventType severity);member this.WriteEntry : string * System.Diagnostics.TraceEventType -> unitPublic Sub WriteEntry (message As String, severity As TraceEventType)参数
- message
- String
必需。 要记录的消息。 如果 message 为 Nothing,则返回一个空字符串。
- severity
- TraceEventType
消息的类型。 默认为 TraceEventType.Information。
例外
消息类型不是 TraceEventType 枚举值之一。
具有部分信任的代码调用该方法,但是写入到需要完全信任的事件日志侦听器。
示例
本示例将演示如何使用 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.Log.WriteEntry更改为 My.Application.Log.WriteEntry 。
注解
方法 WriteEntry 将消息写入应用程序的事件日志侦听器。
在客户端应用程序中 Log ,对象通过 My.Application.Log 对象可用。 在 Web 应用程序中, Log 对象通过 My.Log 对象可用。
若要了解哪些日志侦听器接收 WriteEntry 方法的消息,请参阅 演练:确定 My.Application.Log 写入信息的位置。 可以更改默认日志侦听器。 有关详细信息,请参阅使用应用程序日志。
对于不采用 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 在哪里写入信息 | 
可用性(按项目类型)
| 项目类型 | 可用 | 
|---|---|
| Windows 应用程序 | 是 | 
| 类库 | 是 | 
| 控制台应用程序 | 是 | 
| Windows 控件库 | 是 | 
| Web 控件库 | 否 | 
| Windows 服务 | 是 | 
| 网站 | 是 | 
另请参阅
- TraceEventType
- 对象 (Visual Basic)
- 使用 Application 日志 (Visual Basic)
- 如何:写入日志消息
- 演练:确定 My.Application.Log 写入信息的位置
适用于
WriteEntry(String, TraceEventType, Int32)
将消息写入应用程序的日志侦听器中。
public:
 void WriteEntry(System::String ^ message, System::Diagnostics::TraceEventType severity, int id);public void WriteEntry (string message, System.Diagnostics.TraceEventType severity, int id);member this.WriteEntry : string * System.Diagnostics.TraceEventType * int -> unitPublic Sub WriteEntry (message As String, severity As TraceEventType, id As Integer)参数
- message
- String
必需。 要记录的消息。 如果 message 为 Nothing,则返回一个空字符串。
- severity
- TraceEventType
消息的类型。 默认为 TraceEventType.Information。
- id
- Int32
消息标识符,通常用于相关。 默认情况下,与 相关 entryType ,如表中所述。
例外
消息类型不是 TraceEventType 枚举值之一。
具有部分信任的代码调用该方法,但是写入到需要完全信任的事件日志侦听器。
示例
本示例将演示如何使用 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.Log.WriteEntry将 更改为 My.Application.Log.WriteEntry 。
注解
方法 WriteEntry 将消息写入应用程序的事件日志侦听器。
在客户端应用程序中 Log , 对象通过 My.Application.Log 对象提供。 在 Web 应用程序中, Log 对象通过 My.Log 对象提供。
若要了解哪些日志侦听器接收 WriteEntry 方法的消息,请参阅 演练:确定 My.Application.Log 写入信息的位置。 可以更改默认日志侦听器。 有关详细信息,请参阅使用应用程序日志。
对于不采用 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 在哪里写入信息 | 
可用性(按项目类型)
| 项目类型 | 可用 | 
|---|---|
| Windows 应用程序 | 是 | 
| 类库 | 是 | 
| 控制台应用程序 | 是 | 
| Windows 控件库 | 是 | 
| Web 控件库 | 否 | 
| Windows 服务 | 是 | 
| 网站 | 是 | 
另请参阅
- TraceEventType
- 对象 (Visual Basic)
- 使用 Application 日志 (Visual Basic)
- 如何:写入日志消息
- 演练:确定 My.Application.Log 写入信息的位置