Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

Log Class

Definition

Namespace:
Microsoft.VisualBasic.Logging
Assembly:
Microsoft.VisualBasic.dll
Assembly:
Microsoft.VisualBasic.Forms.dll
Source:
Log.vb
Source:
Log.vb
Source:
Log.vb
Source:
Log.vb
Source:
Log.vb

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Provides a property and methods for writing event and exception information to the application's log listeners.

public ref class Log
public class Log
type Log = class
Public Class Log
Inheritance
Log
Derived

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.

Private Sub GetOpenFormTitles()
 Dim formTitles As New Collection

 Try
 For Each f As Form In My.Application.OpenForms
 ' Use a thread-safe method to get all form titles.
 formTitles.Add(GetFormTitle(f))
 Next
 Catch ex As Exception
 formTitles.Add("Error: " & ex.Message)
 End Try

 Form1.ListBox1.DataSource = formTitles
End Sub

Private Delegate Function GetFormTitleDelegate(f As Form) As String
Private Function GetFormTitle(f As Form) As String
 ' Check if the form can be accessed from the current thread.
 If Not f.InvokeRequired Then
 ' Access the form directly.
 Return f.Text
 Else
 ' Marshal to the thread that owns the form. 
 Dim del As GetFormTitleDelegate = AddressOf GetFormTitle
 Dim param As Object() = {f}
 Dim result As System.IAsyncResult = f.BeginInvoke(del, param)
 ' Give the form's thread a chance process function.
 System.Threading.Thread.Sleep(10)
 ' Check the result.
 If result.IsCompleted Then
 ' Get the function's return value.
 Return "Different thread: " & f.EndInvoke(result).ToString
 Else
 Return "Unresponsive thread"
 End If
 End If
End Function

Remarks

The My.Application.Log object provides a straightforward entry point from which to access the .NET Framework's logging services. The WriteEntry and WriteException methods write messages to the application's log listeners. The listeners can be configured by the application's configuration file. For more information, see Walkthrough: Changing Where My.Application.Log Writes Information and Working with Application Logs.

The My.Application.Log object is available only for client applications. For Web applications, use My.Log. For more information, see AspLog.

The following table lists examples of tasks involving the My.Application.Log object.

To See
Write event information to the application's log listeners How to: Write Log Messages
Write exception information to the application's log listeners How to: Log Exceptions
Determine where My.Application.Log writes information Walkthrough: Determining Where My.Application.Log Writes Information

Constructors

Name Description
Log()

Initializes a new instance of the Log class.

Log(String)

Initializes a new instance of the Log class.

Properties

Name Description
DefaultFileLogWriter

Gets the file the FileLogTraceListener object that underlies the Log object.

TraceSource

Gets to the TraceSource object that underlies the Log object.

Methods

Name Description
Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
InitializeWithDefaultsSinceNoConfigExists()

Creates a new FileLogTraceListener object and adds it to the Listeners collection.

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)
WriteEntry(String, TraceEventType, Int32)

Writes a message to the application's log listeners.

WriteEntry(String, TraceEventType)

Writes a message to the application's log listeners.

WriteEntry(String)

Writes a message to the application's log listeners.

WriteException(Exception, TraceEventType, String, Int32)

Writes exception information to the application's log listeners.

WriteException(Exception, TraceEventType, String)

Writes exception information to the application's log listeners.

WriteException(Exception)

Writes exception information to the application's log listeners.

Applies to

See also


Feedback

Was this page helpful?