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.Log

Gets or sets the name of the log to read from and write to.

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

Property Value

The name of the log. This can be "Application", "System", "Security", an application-specific log or a custom log name. The default is an empty string ("").

Remarks

Three log files exist by default on the server: Application, System, and Security. Applications and services use the Application log file. Device drivers use the System log file. The system generates success and failure audit events in the Security log when auditing is turned on. If you have other applications installed, like Active Directory on Windows 2000, there may be other default log files. In addition, you can create custom log files on a local or remote computer. Custom logs help you organize your entries in a more granular way than is allowed when your components write events to the default Application log.

If you write to an event log, it is not enough to specify the Log property. 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.

If the Source property has not been specified, a call to Log returns an empty string if Log has not been explicitly set to another value. If the Source has been specified, Log returns the name of the log to which that source has been registered.

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 Log property for that EventLog without changing the value of Source or calling DeleteEventSource first. Attempting to change the Log property once the Source property has been set will throw an exception.

There is no way, using methods in EventLog, to create a new log using the Log property alone (that is, without specifying a Source for the Log). You can call CreateEventSource, passing in a new log name as a parameter and then call DeleteEventSource. However, when used in applications, the intent is usually either to create (and write entries to) new application-specific logs, or to read from existing logs.

The Log value cannot be an empty string if Source has not been set. If the Log 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 | MachineName | Source | Entries | Exists | Delete | CreateEventSource | EventLog.EventLogEntryCollection