24/7/365 Support

Create or Remove an Event Log

Problem

You want to create or remove an event log.

Solution

To create an event log, use the [System.Diagnostics.EventLog]:: CreateEventSource() method from the .NET Framework:

$newLog =

NewObject Diagnostics.EventSourceCreationData

"PowerShellCookbook","ScriptEvents"

[Diagnostics.EventLog]::CreateEventSource($newLog)

To delete an event log, use the [System.Diagnostics.EventLog]::Delete() method from the .NET Framework:

[Diagnostics.EventLog]::Delete("ScriptEvents")

Discussion

The [System.Diagnostics.EventLog]::CreateEventSource() method from the .NET Framework registers a new event source (PowerShellCookbook in the solution) to write entries to an event log (ScriptEvents in the solution). If the event log does not exist, the CreateEventSource() method creates the event log.

The [System.Diagnostics.EventLog]::Delete() method from the .NET Framework deletes the event log altogether, along with any event sources associated with it. To delete only a specific event source, use the [System.Diagnostics.EventLog]:: DeleteEventSource() method from the .NET Framework.

Be careful when deleting event logs, as it is difficult to recreate all the event sources if you delete the wrong log by accident.

Help Category:

Get Windows Dedicated Server

Only reading will not help you, you have to practice it! So get it now.

Processor RAM Storage Server Detail
Intel Atom C2350 1.7 GHz 2c/2t 4 GB DDR3 1× 1 TB (HDD SATA) Configure Server
Intel Atom C2350 1.7 GHz 2c/2t 4 GB DDR3 1× 128 GB (SSD SATA) Configure Server
Intel Atom C2750 2.4 GHz 8c/8t 8 GB DDR3 1× 1 TB (HDD SATA) Configure Server
Intel Xeon E3-1230 v2 3.3 GHz 4c/8t 16 GB DDR3 1× 256 GB (SSD SATA) Configure Server
Intel Atom C2350 1.7 GHz 2c/2t 4 GB DDR3 1× 250 GB (SSD SATA) Configure Server

What Our Clients Say