Export (0) Print
Expand All

EventLog.MachineName Property

Gets or sets the name of the computer on which to read or write events.

Namespace: System.Diagnostics
Assembly: System (in system.dll)

'Declaration
Public Property MachineName As String
'Usage
Dim instance As EventLog
Dim value As String

value = instance.MachineName

instance.MachineName = value
/** @property */
public String get_MachineName ()

/** @property */
public void set_MachineName (String value)

public function get MachineName () : String

public function set MachineName (value : String)

Not applicable.

Property Value

The name of the server on which the event log resides. The default is the local computer (".").

Exception typeCondition

ArgumentException

The computer name is invalid.

If you write to an event log, you must associate a Source with your event log object to connect it to a particular log. It is not necessary to specify the Source property when only reading from a log. You can specify only the Log name and MachineName (server computer name).

NoteNote:

You need not specify the MachineName if you are connecting to a log. If you do not specify the MachineName, the local computer (".") is assumed.

A source can only be registered to one log at a time. If the Source property was set for an instance of EventLog, you cannot change the MachineName property for that EventLog without changing the value of Source or calling DeleteEventSource first. If you change the MachineName property, the EventLog closes all handles and reattaches to the log and source on the new computer.

The MachineName value cannot be an empty string. If it is not explicitly set, it defaults to the local computer (".").

The following example reads entries in the event log, "NewEventLog", on a specified computer.

Imports System
Imports System.Diagnostics
Imports Microsoft.VisualBasic

Class MySample
    Public Shared Sub Main()
        Dim myNewLog As New EventLog()
        myNewLog.Log = "NewEventLog"
        myNewLog.MachineName = "MyServer"
        Dim entry As EventLogEntry
        For Each entry In  myNewLog.Entries
            Console.WriteLine((ControlChars.Tab & "Entry: " & entry.Message))
        Next entry
    End Sub ' Main
End Class ' MySample

import System.*;
import System.Diagnostics.*;
import System.Collections.*;

class MySample
{
    public static void main(String[] args)
    {
        EventLog myNewLog = new EventLog();
        myNewLog.set_Log("NewEventLog");
        myNewLog.set_MachineName("MyServer");        
        EventLogEntry entry;
        IEnumerator objEnum = myNewLog.get_Entries().GetEnumerator();
        while (objEnum.MoveNext()) {
            entry = (EventLogEntry)objEnum.get_Current();
            Console.WriteLine("\tEntry: " + entry.get_Message());
        }
    } //main
} //MySample

Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft