How to create Windows EventLog source from command line?

后端 未结 8 1533
温柔的废话
温柔的废话 2020-11-27 09:28

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 priviledg

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 10:02

    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:

    $evt=new-object System.Diagnostics.Eventlog(“Define Logbook”)
    $evt.Source=”Define Source”
    $evtNumber=Define Eventnumber
    $evtDescription=”Define description”
    $infoevent=[System.Diagnostics.EventLogEntryType]::Define error level
    $evt.WriteEntry($evtDescription,$infoevent,$evtNumber) 
    

    Sample:

    $evt=new-object System.Diagnostics.Eventlog(“System”)
    $evt.Source=”Tcpip”
    $evtNumber=4227
    $evtDescription=”This is a Test Event”
    $infoevent=[System.Diagnostics.EventLogEntryType]::Warning
    $evt.WriteEntry($evtDescription,$infoevent,$evtNumber)
    

提交回复
热议问题