NLog: can't write to event log

后端 未结 1 1715
说谎
说谎 2020-12-31 06:49

I can\'t write to the event log with NLog. I\'ve been able to write to the console and to a file. I\'ve turned on exceptions in NLog and am receiving no feedback from NLog

相关标签:
1条回答
  • 2020-12-31 07:13

    From nlog forum post

    To be able to write to the EventLog an application must be registered as an event source. If you run VS as admin this happens automatically. If you create an installer and install your application it gets registered.

    To register an app manually as event source I use the following script:

    Set Args = WScript.Arguments
    If Args.Count < 1 then
        WScript.Echo "USAGE: CreateEventSource.vbs <EventSourceName>"
        WScript.Quit
    End If
    EventSourceName = Args(0)
    
    Set WshShell = WScript.CreateObject("WScript.Shell")
    
    'Create event source
    KeyName = "HKLM\SYSTEM\CurrentControlSet\Services\Eventlog\Application\" & EventSourceName & "\EventMessageFile"
    'Change path to .NET Framework version used
    WshShell.RegWrite KeyName,"%windir%\Microsoft.NET\Framework64\v2.0.50727\EventLogMessages.dll", "REG_EXPAND_SZ" 
    
    0 讨论(0)
提交回复
热议问题