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?
However the cmd/batch version works you can run into an issue when you want to define an eventID which is higher then 1000. For event creation with an eventID of 1000+ i'll use powershell like this:
Sample:
Or just use the command line command:
Eventcreate
eventcreate2 allows you to create custom logs, where eventcreate does not.
you can create your own custom event by using diagnostics.Event log class. Open a windows application and on a button click do the following code.
"MyNewLog" means the name you want to give to your log in event viewer.
for more information check this link [ http://msdn.microsoft.com/en-in/library/49dwckkz%28v=vs.90%29.aspx]
You can also use Windows PowerShell with the following command:
Make sure to check that the source does not exist before calling CreateEventSource, otherwise it will throw an exception.
For more info:
If someone is interested, it is also possible to create an event source manually by adding some registry values.
Save the following lines as a .reg file, then import it to registry by double clicking it:
This creates an event source named
YOUR_EVENT_SOURCE_NAME_GOES_HERE
.