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

Closes the event log and releases read and write handles.

[Visual Basic]
Overridable Public Sub Close()
[C#]
public virtual void Close();
[C++]
public: virtual void Close();
[JScript]
public function Close();

Exceptions

Exception Type Condition
Win32Exception The event log's read handle or write handle was not released successfully.

Remarks

Call Close before calling Delete on the event log.

The Close method is automatically called by the Dispose method. You do not need to invoke Close explicitly before calling Dispose.

Example [Visual Basic]

following example closes an event log specified by the source "mySource", and deletes the source. This does not delete the log to which the source is registered (use Delete for that), only the source and its registration. The log can be opened again by creating another source with CreateEventSource and registering it to the log.

The local event log instance is created only in order to call Close on the log. All other methods used are static (in Visual Basic Shared) and should be called on the EventLog class itself.

Import the System.Diagnostics namespace for this example.

[Visual Basic]

Private Sub CloseLog()
    'Declare and instantiate an event log.
    Dim evtLog As EventLog
    evtLog = New EventLog
    'Declare a source called "mySource"
    Dim source As String
    source = "mySource"

    'Verify that the source exists.
    If EventLog.SourceExists(source) Then
        'Connect the event log to the source.
        evtLog.Source = source
        'Close the log so that it does not receive new entries.
        evtLog.Close()
        EventLog.DeleteEventSource(source)
    End If
End Sub

See Also

EventLog Class | EventLog Members | System.Diagnostics Namespace | Delete | Clear | Dispose