How to create Windows EventLog source from command line?
Try "eventcreate.exe"
An example:
eventcreate /ID 1 /L APPLICATION /T INFORMATION /SO MYEVENTSOURCE /D "My first log"
This will create a new event source named MYEVENTSOURCE
under APPLICATION
event log as INFORMATION
event type.
I think this utility is included only from XP onwards.
Further reading
Windows IT Pro: JSI Tip 5487. Windows XP includes the EventCreate utility for creating custom events.
Type
eventcreate /?
in CMD promptMicrosoft TechNet: Windows Command-Line Reference: Eventcreate
SS64: Windows Command-Line Reference: Eventcreate
Try PowerShell 2.0's EventLog cmdlets
Throwing this in for PowerShell 2.0 and upwards:
Run
New-EventLog
once to register the event source:New-EventLog -LogName Application -Source MyApp
Then use
Write-EventLog
to write to the log:Write-EventLog -LogName Application -Source MyApp -EntryType Error -Message "Immunity to iocaine powder not detected, dying now" -EventId 1
You can also use Windows PowerShell with the following command:
if ([System.Diagnostics.EventLog]::SourceExists($source) -eq $false) { [System.Diagnostics.EventLog]::CreateEventSource($source, "Application")}
Make sure to check that the source does not exist before calling CreateEventSource, otherwise it will throw an exception.
For more info: