Creating Your Own Event Logs

One way to handle a plethora of events is to create your own event log. This makes the information readily available and greatly simplifies the search task. To create a new event log, use the CreateEventSource method from the System.Diagnostics.EventLog class and tell it both the name of the source and the name of the log. An event source can only be associated with a single event log, although a single event log can hold many sources, as you observed in the GetLogSources.ps1 script. To avoid errors, use the SourceExists method and give it the name of the source you are looking for. If the source does not exist, create the source and event log at the same time. However, if the source does exist, then write an error ...

Get Windows PowerShell™ Scripting Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.