Provides the System.Diagnostics.EventLog class, which allows the applications to use the Windows event log service. Commonly Used Types: System.Diagnostics.EventLog
$ dotnet add package System.Diagnostics.EventLogThis package provides types that allow applications to interact with the Windows Event Log service.
When an error occurs in a Windows machine, the system administrator or support representative must determine what caused the error, attempt to recover any lost data, and prevent the error from recurring. It is helpful if applications, the operating system, and other system services record important events, such as low-memory conditions or excessive attempts to access a disk. The system administrator can then use the Windows Event Log to help determine what conditions caused the error and identify the context in which it occurred.
if(!EventLog.SourceExists("MySource"))
{
// An event log source should not be created and immediately used.
// There is a latency time to enable the source, it should be created
// prior to executing the application that uses the source.
// Execute this sample a second time to use the new source.
EventLog.CreateEventSource("MySource", "MyNewLog");
Console.WriteLine("Event source created. Exiting, execute the application a second time to use the source.");
// The source is created. Exit the application to allow it to be registered.
return;
}
EventLog myLog = new();
myLog.Source = "MySource";
myLog.WriteEntry("Writing an informational entry to the event log.");
Notes:
System.Diagnostics.EventLog class.The main types provided by this library are:
Under the System.Diagnostics namespace, the main types are:
Under the System.Diagnostics.Eventing.Reader namespace, the main types are:
System.Diagnostics.EventLog is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.