views:

7421

answers:

6

I'm creating an ASP.NET application that will log some stuff to Windows EventLog. To do this an event source has to be created first. This requires administrative priviledges so I cannot do it in the ASP.NET app.

Is there an existing command-line application that is bundled with Windows that can create an event log source, or must I roll out my own?

+2  A: 

Roll your own console app with...

EventLog.CreateEventSource(source, "Application")

See Initializing an EventLog Source

Ed Guiness
Yap, I know that one... just wondered if there is something already existing.
Vilx-
A: 

Or just use the command line command:

Eventcreate

Greg
+13  A: 

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.

Hope this helps! For more information:

or eventcreate /? in CMD prompt.

I think this utility is included only from XP onwards.

MSV Muthu
A: 

MSV Muthu, YOU ROCK.

I was trying to create the event source using code-

EventLog.CreateEventSource(source, "Application") but permissions were preventing it.

used this- eventcreate /ID 1 /L APPLICATION /T INFORMATION /SO MYEVENTSOURCE /D "My first log"

it works now.

A: 

eventcreate2 allows you to create custom logs, where eventcreate does not.

nbolton
+1  A: 

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:

Luis Rocha