Edit

Share via


Log.WriteEntry Method

Definition

Writes a message to the application's log listeners.

Overloads

WriteEntry(String)

Writes a message to the application's log listeners.

WriteEntry(String, TraceEventType)

Writes a message to the application's log listeners.

WriteEntry(String, TraceEventType, Int32)

Writes a message to the application's log listeners.

WriteEntry(String)

Writes a message to the application's log listeners.

public:
 void WriteEntry(System::String ^ message);
public void WriteEntry (string message);
member this.WriteEntry : string -> unit
Public Sub WriteEntry (message As String)

Parameters

message
String

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

Exceptions

Code with partial trust calls the method, but writes to an event log listener that requires full trust.

Examples

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.

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.

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

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

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

See also

Applies to

WriteEntry(String, TraceEventType)

Writes a message to the application's log listeners.

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 -> unit
Public Sub WriteEntry (message As String, severity As TraceEventType)

Parameters

message
String

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

severity
TraceEventType

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

Exceptions

The message type is not one of the TraceEventType enumeration values.

Code with partial trust calls the method, but writes to an event log listener that requires full trust.

Examples

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.

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.

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

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

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

See also

Applies to

WriteEntry(String, TraceEventType, Int32)

Writes a message to the application's log listeners.

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 -> unit
Public Sub WriteEntry (message As String, severity As TraceEventType, id As Integer)

Parameters

message
String

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

severity
TraceEventType

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

id
Int32

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

Exceptions

The message type is not one of the TraceEventType enumeration values.

Code with partial trust calls the method, but writes to an event log listener that requires full trust.

Examples

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.

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.

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

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

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

See also

Applies to