如何使用NLog從windows服務中的動態加載的dll寫入NLog。如何使用Nlog從動態加載的dll在windows服務中寫入eventLog
使用NLog 2.0.1 我有一個Windows服務,動態加載一個DLL,從我正在使用(嘗試)NLog日誌記錄到事件日誌。 eventLog是自定義的,由服務安裝程序創建。
錯誤:
Service cannot be started. System.Reflection.TargetInvocationException:
Exception has been thrown by the target of an invocation.
---> System.TypeInitializationException: The type initializer for 'MyService.Worker' threw an exception.
---> NLog.NLogConfigurationException: Error during initialization of EventLog Target[eventLog_wrapped]
---> System.IO.IOException: The network path was not found.
at Microsoft.Win32.RegistryKey.Win32ErrorStatic(Int32 errorCode, String str)
at Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(RegistryHive hKey, String machineName, RegistryView view)
at System.Diagnostics.EventLog.GetEventLogRegKey(String machine, Boolean writable)
at System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean readOnly, Boolean wantToCreate)
at System.Diagnostics.EventLog._InternalLogNameFromSourceName(String source, String machineName)
at System.Diagnostics.EventLog.LogNameFromSourceName(String source, String machineName)
at NLog.Targets.EventLogTarg...
我創建了一個winform應用程序來測試記錄和日誌記錄正常工作,但是當我嘗試做同樣的事情在我的服務這是行不通的。
我試着運行「本地系統」和「網絡服務」下的服務,我得到了同樣的錯誤。至於「網絡路徑....」沒有網絡路徑被訪問,所以我不知道這是什麼試圖告訴我。
我NLOG配置/目標是:
<variable name="appName" value="MyApp" />
<variable name="source" value="MySource" />
<target xsi:type="EventLog"
name="log"
log="My Service"
source="${source}"
machineName="."
layout="${callsite}${newline} ${message}${newline}${exception:format=ToString}"
/>
如何得到這個工作任何想法,將不勝感激。