Udostępnij za pośrednictwem


WriteEntry Method (My.Application.Log and My.Log)

Writes a message to the application's log listeners.

' 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 _
)

Parameters

  • message
    Required. The message to log. If message is Nothing, an empty string is used.

  • severity
    The type of message. By default, TraceEventType.Information.

  • id
    Message identifier, typically used for correlation. By default, related to entryType as described in the table.

Exceptions

The following conditions cause an exception:

Remarks

The WriteEntry method writes a message to the application's event log listeners.

In client applications, the Log object is available through the My.Application.Log object. In Web applications, the Log object is available through the My.Log object.

To learn which log listeners receive the WriteEntry method's messages, see Walkthrough: Determining Where My.Application.Log Writes Information. You can change default log listeners. For more information, see Working with Application Logs in Visual Basic.

For overloads that do not take the id argument, the id written to the log is defined by the following table.

severity

Default id

Information

0

Warning

1

Error

2

Critical

3

Start

4

Stop

5

Suspend

6

Resume

7

Verbose

8

Transfer

9

Tasks

The following table lists examples of tasks involving the WriteEntry method.

To

See

Write event information to the application's log listeners

How to: Write Log Messages

Determine where Log writes information

Walkthrough: Determining Where My.Application.Log Writes Information

Example

This example shows how to use the My.Application.Log.WriteEntry method to log tracing information. For more information, see How to: Write Log Messages.

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

This code example can run only within a client application. Change My.Application.Log.WriteEntry to My.Log.WriteEntry for Web applications.

Requirements

Namespace:Microsoft.VisualBasic.Logging

Class:Log

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

Availability by Project Type

Project type

Available

Windows Application

Yes

Class Library

Yes

Console Application

Yes

Windows Control Library

Yes

Web Control Library

No

Windows Service

Yes

Web Site

Yes

Permissions

The following permission may be necessary:

Permission

Description

FileIOPermission

Controls the ability to access files and folders. Associated enumeration: Unrestricted.

For more information, see Code Access Security and Requesting Permissions.

See Also

Tasks

How to: Write Log Messages

Walkthrough: Determining Where My.Application.Log Writes Information

Concepts

Working with Application Logs in Visual Basic

Reference

My.Application.Log Object

My.Log Object

System.Diagnostics.TraceEventType

Log.WriteEntry