NLog与NLog.Targets.Syslog - 对象引用错误

时间:2017-01-10 06:52:54

标签: nlog

我正在尝试使用NLog和NLog.Targets.Syslog登录papertrail系统,并且当我调用时,NLog无法从NLog.config加载目标

Logger logger = LogManager.GetCurrentClassLogger();

并抛出异常 对象引用未设置为对象的实例。

at NLog.Targets.Syslog.Settings.Rfc3164Config..ctor()
   at NLog.Targets.Syslog.Settings.MessageBuilderConfig..ctor()
   at NLog.Targets.Syslog.SyslogTarget..ctor()

堆栈跟踪

at NLog.Config.XmlLoggingConfiguration.Initialize(XmlReader reader, String fileName, Boolean ignoreErrors)
   at NLog.Config.XmlLoggingConfiguration..ctor(String fileName, Boolean ignoreErrors, LogFactory logFactory)
   at NLog.LogFactory.LoadLoggingConfiguration(String configFile)
   at NLog.LogFactory.get_Configuration()
   at NLog.LogFactory.GetLogger(LoggerCacheKey cacheKey)
   at NLog.LogFactory.GetLogger(String name)
   at NLog.LogManager.GetCurrentClassLogger()
   at NLogPaperTrail.Controllers.HomeController.Index() in I:\Temp\Proj\tempsolution\NLogPaperTrail\NLogPaperTrail\Controllers

这是NLog.config

    <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true"     ThrowExceptions = "true"  >

 <extensions>

       <add assembly="NLog.Targets.Syslog" />
    </extensions>

    <targets>
        <target name="syslog" xsi:type="Syslog" syslogserver="host.papertrailapp.com" port="5677" facility="Local7"/>

   </targets>

    <rules>

     <logger name="*" minLevel="Trace" appendTo="syslog"/>
    </rules>
</nlog>

任何人都可以提供帮助或提供您的建议吗?

1 个答案:

答案 0 :(得分:1)

此处也有报道:

https://github.com/NLog/NLog/issues/1894

并在此处解决(SysLog Target Ver.3.0.1)

https://github.com/graffen/NLog.Targets.Syslog/pull/53