<PackageReference Include="System.Diagnostics.EventLog" Version="9.0.2" />

EventLogSession

public class EventLogSession : IDisposable
Used to access the Event Log service on the local computer or a remote computer so you can manage and gather information about the event logs and event providers on the computer.
public static EventLogSession GlobalSession { get; }

Gets a static predefined session object that is connected to the Event Log service on the local computer.

public EventLogSession()

Initializes a new EventLogSession object, establishes a connection with the local Event Log service.

public EventLogSession(string server)

Initializes a new EventLogSession object, and establishes a connection with the Event Log service on the specified computer. The credentials (user name and password) of the user who calls the method is used for the credentials to access the remote computer.

public EventLogSession(string server, string domain, string user, SecureString password, SessionAuthentication logOnType)

Initializes a new EventLogSession object, and establishes a connection with the Event Log service on the specified computer. The specified credentials (user name and password) are used for the credentials to access the remote computer.

Cancels any operations (such as reading an event log or subscribing to an event log) that are currently active for the Event Log service that this session object is connected to.

public void ClearLog(string logName)

Clears events from the specified event log.

public void ClearLog(string logName, string backupPath)

Clears events from the specified event log, and saves the cleared events to the specified file.

public void Dispose()

Releases all the resources used by this object.

protected virtual void Dispose(bool disposing)

Releases the unmanaged resources used by this object, and optionally releases the managed resources.

public void ExportLog(string path, PathType pathType, string query, string targetFilePath)

Exports events into an external log file. The events are stored without the event messages.

public void ExportLog(string path, PathType pathType, string query, string targetFilePath, bool tolerateQueryErrors)

Exports events into an external log file. A flag can be set to indicate that the method will continue exporting events even if the specified query fails for some logs. The events are stored without the event messages.

public void ExportLogAndMessages(string path, PathType pathType, string query, string targetFilePath)

Exports events and their messages into an external log file.

public void ExportLogAndMessages(string path, PathType pathType, string query, string targetFilePath, bool tolerateQueryErrors, CultureInfo targetCultureInfo)

Exports events and their messages into an external log file. A flag can be set to indicate that the method will continue exporting events even if the specified query fails for some logs. The event messages are exported in the specified language.

public EventLogInformation GetLogInformation(string logName, PathType pathType)

Gets an object that contains runtime information for the specified event log.

public IEnumerable<string> GetLogNames()

Gets an enumerable collection of all the event log names that are registered with the Event Log service.

public IEnumerable<string> GetProviderNames()

Gets an enumerable collection of all the event provider names that are registered with the Event Log service. An event provider is an application that publishes events to an event log.