EventLog.MachineName Property
Definition
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.
Gets or sets the name of the computer on which to read or write events.
public:
property System::String ^ MachineName { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.SettingsBindable(true)]
public string MachineName { get; set; }
public string MachineName { get; set; }
[<System.ComponentModel.SettingsBindable(true)>]
member this.MachineName : string with get, set
member this.MachineName : string with get, set
Public Property MachineName As String
Property Value
The name of the server on which the event log resides. The default is the local computer (".").
- Attributes
Exceptions
The computer name is invalid.
Examples
The following example reads entries in the event log, "NewEventLog", on a specified computer.
#using <System.dll>
using namespace System;
using namespace System::Diagnostics;
int main()
{
EventLog^ myNewLog = gcnew EventLog;
myNewLog->Log = "NewEventLog";
myNewLog->MachineName = "MyServer";
System::Collections::IEnumerator^ myEnum = myNewLog->Entries->GetEnumerator();
while ( myEnum->MoveNext() )
{
EventLogEntry^ entry = safe_cast<EventLogEntry^>(myEnum->Current);
Console::WriteLine( "\tEntry: {0}", entry->Message );
}
}
using System;
using System.Diagnostics;
class MySample{
public static void Main(){
EventLog myNewLog = new EventLog();
myNewLog.Log = "NewEventLog";
myNewLog.MachineName = "MyServer";
foreach(EventLogEntry entry in myNewLog.Entries){
Console.WriteLine("\tEntry: " + entry.Message);
}
}
}
Imports System.Diagnostics
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
End Class
Remarks
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).
Note
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 (".").