NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

EventLog.MachineName

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

[Visual Basic]
Overridable Public Property MachineName As String
[C#]
public string MachineName {virtual get; virtual set;}
[C++]
public: __property virtual String* get_MachineName();
public: __property virtual void set_MachineName(String*);
[JScript]
public function get MachineName() : String;
public function set MachineName(String);

Property Value

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

Exceptions

Exception Type Condition
ArgumentException The computer name is invalid.

Remarks

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

Note   You are not explicitly required to specify the MachineName if you are connecting to a log by specifying a Log/ MachineName pair. 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 has been set for an instance of EventLog, you can't subsequently 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 reattach to the log and source on the new computer.

The MachineName value cannot be set to an empty string. However, if it is not explicitly set, it defaults to the local computer ("."). If the MachineName value changes, the event log is closed and all event handles are released.

Example [Visual Basic]

The following example uses the Log and MachineName of an EventLog to connect to an event log. Then it displays the Entries in the log.

Because the procedure reads rather than writes entries, it is only necessary to set the Log and MachineName. The Source is only necessary for WriteEntry. Alternately, you can leave the MachineName empty and the local computer will be assumed.

This example assumes you already have a custom event log "myNewLog" on the computer named "myComputer".

Import the System.Diagnostics namespace for this example.

[Visual Basic]

Private Sub GetLogEntries()
    'Declare a new event log
    Dim evtLog As EventLog
    'This is used in the for loop iterating through the evtLog.Entries
    Dim entry As EventLogEntry

    'Instantiate an event log.
    evtLog = New EventLog
    'Set the server and log names so we can read from the log.
    evtLog.MachineName = "myComputer"
    evtLog.Log = "myNewLog"


    'Display the entries in order to the screen.
    For Each entry In evtLog.Entries
        Console.WriteLine("Message: " + entry.Message)
    Next
End Sub

See Also

EventLog Class | EventLog Members | System.Diagnostics Namespace | Log | Source | CreateEventSource | DeleteEventSource | Delete | SourceExists | Exists | GetEventLogs