[windows] 명령 줄에서 Windows EventLog 소스를 만드는 방법은 무엇입니까?

Windows EventLog에 물건을 기록하는 ASP.NET 응용 프로그램을 만들고 있습니다. 이를 위해서는 먼저 이벤트 소스를 작성해야합니다. 여기에는 관리 권한이 필요하므로 ASP.NET 앱에서는 관리 권한이 없습니다.

이벤트 로그 소스를 만들 수있는 Windows와 함께 번들로 제공되는 기존 명령 줄 응용 프로그램이 있습니까? 아니면 직접 배포해야합니까?



답변

“eventcreate.exe”를 사용해보십시오

예를 들면 :

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

그러면 이벤트 로그 아래에 이벤트 유형 으로 이름 지정된 새 이벤트 소스 가 작성됩니다 .MYEVENTSOURCEAPPLICATIONINFORMATION

이 유틸리티는 XP 이후로만 포함되어 있다고 생각합니다.

추가 자료


답변

PowerShell 2.0의 EventLog cmdlet을 사용해보십시오.

PowerShell 2.0 이상에서 이것을 던졌습니다.

  • New-EventLog이벤트 소스를 등록하려면 한 번 실행하십시오 .

    New-EventLog -LogName Application -Source MyApp
    
  • 그런 다음을 사용 Write-EventLog하여 로그에 씁니다.

    Write-EventLog
        -LogName Application
        -Source MyApp
        -EntryType Error
        -Message "Immunity to iocaine powder not detected, dying now"
        -EventId 1
    

답변

다음 명령으로 Windows PowerShell을 사용할 수도 있습니다.

if ([System.Diagnostics.EventLog]::SourceExists($source) -eq $false) {
    [System.Diagnostics.EventLog]::CreateEventSource($source, "Application")
}

CreateEventSource를 호출하기 전에 소스가 존재하지 않는지 확인하십시오. 그렇지 않으면 예외가 발생합니다.

더 많은 정보를 위해서:


답변

eventcreate2를 사용하면 eventcreate 가 아닌사용자 지정 로그를 만들 수 있습니다.


답변

누군가 관심이 있다면 일부 레지스트리 값을 추가하여 이벤트 소스를 수동으로 작성할 수도 있습니다.

다음 줄을 .reg 파일로 저장 한 다음 두 번 클릭하여 레지스트리로 가져옵니다.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\YOUR_EVENT_SOURCE_NAME_GOES_HERE]
"EventMessageFile"="C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\EventLogMessages.dll"
"TypesSupported"=dword:00000007

이라는 이벤트 소스가 생성 YOUR_EVENT_SOURCE_NAME_GOES_HERE됩니다.


답변

또는 명령 행 명령을 사용하십시오.

이벤트 작성


답변

그러나 cmd / 배치 버전이 작동하면 1000보다 높은 eventID를 정의하려고 할 때 문제가 발생할 수 있습니다. eventID가 1000 이상인 이벤트를 만들려면 다음과 같이 powershell을 사용합니다.

$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)

견본:

$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)