【问题标题】:Please help convert NLog v1.1 to NLog v2.0请帮助将 NLog v1.1 转换为 NLog v2.0
【发布时间】:2011-09-20 17:51:16
【问题描述】:

我想在我们的 Silverlight v4.0 项目中使用 Sharedcache (sharedcache.codeplex.com)。但是,我们使用 NLog v2.0 进行客户端日志记录。 SharedCache 当前版本仅支持 NLog v1.1,它将与我们的 Web 服务器上的 NLog v2.0 发生冲突。

所以我决定将 Sharedcache windows 服务转换为使用 NLog v2.0。编译成功。但是一旦我启动服务,我就收到了这个错误。熟悉NLog的人可以帮忙吗?我认为它在抱怨布局。

这里是windows服务配置文件:

  <nlog autoReload="true" throwExceptions="true">
<targets async="true">
  <target name="shared_cache_general" type="File" layout="${longdate}|${level:uppercase=true}|${aspnet-request:item=logSession}|${message}" filename="C:\temp\logs\server\${date:format=yyyy-MM-dd}_shared_cache_general_log.txt"/>
  <target name="shared_cache_traffic" type="File" layout="${longdate}|${level:uppercase=true}|${aspnet-request:item=logSession}|${message}" filename="C:\temp\logs\server\${date:format=yyyy-MM-dd}_shared_cache_traffic_log.txt"/>
  <target name="shared_cache_tracking" type="File" layout="${longdate}|${level:uppercase=true}|${aspnet-request:item=logSession}|${message}" filename="C:\temp\logs\server\${date:format=yyyy-MM-dd}_shared_cache_tracking_log.txt"/>
  <target name="shared_cache_sync" type="File" layout="${longdate}|${level:uppercase=true}|${aspnet-request:item=logSession}|${message}" filename="C:\temp\logs\server\${date:format=yyyy-MM-dd}_shared_cache_sync_log.txt"/>
  <target name="shared_cache_memory" type="File" layout="${longdate}|${level:uppercase=true}|${aspnet-request:item=logSession}|${message}" filename="C:\temp\logs\server\${date:format=yyyy-MM-dd}_shared_cache_memory_log.txt"/>
</targets>
<rules>
  <logger name="General" minlevel="Debug" writeTo="shared_cache_general" final="true"/>
  <logger name="Traffic" minlevel="Debug" writeTo="shared_cache_traffic" final="true"/>
  <logger name="Tracking" minlevel="Debug" writeTo="shared_cache_tracking" final="true"/>
  <logger name="Sync" minlevel="Debug" writeTo="shared_cache_sync" final="true"/>
  <logger name="Memory" minlevel="Debug" writeTo="shared_cache_memory" final="true"/>
  <logger name="*" minlevel="Debug" writeTo="shared_cache_general"/>
  <logger name="*" minlevel="Info" writeTo="shared_cache_general"/>
</rules>

在 Visual Studio 中启动服务时,出现以下 NLog 异常:

{"Error when setting property 'Layout' on File Target[shared_cache_general]"}


at NLog.Internal.PropertyHelper.SetPropertyFromString(Object o, String name, String value, ConfigurationItemFactory configurationItemFactory) in c:\NLogBuild\src\NLog\Internal\PropertyHelper.cs:line 107
   at NLog.Config.XmlLoggingConfiguration.ConfigureObjectFromAttributes(Object targetObject, NLogXmlElement element, Boolean ignoreType) in c:\NLogBuild\src\NLog\Config\XmlLoggingConfiguration.cs:line 828
   at NLog.Config.XmlLoggingConfiguration.ParseTargetElement(Target target, NLogXmlElement targetElement) in c:\NLogBuild\src\NLog\Config\XmlLoggingConfiguration.cs:line 562
   at NLog.Config.XmlLoggingConfiguration.ParseTargetsElement(NLogXmlElement targetsElement) in c:\NLogBuild\src\NLog\Config\XmlLoggingConfiguration.cs:line 538
   at NLog.Config.XmlLoggingConfiguration.ParseNLogElement(NLogXmlElement nlogElement, String baseDirectory) in c:\NLogBuild\src\NLog\Config\XmlLoggingConfiguration.cs:line 344
   at NLog.Config.XmlLoggingConfiguration.ParseTopLevel(NLogXmlElement content, String baseDirectory) in c:\NLogBuild\src\NLog\Config\XmlLoggingConfiguration.cs:line 301
   at NLog.Config.XmlLoggingConfiguration.Initialize(XmlReader reader, String fileName, Boolean ignoreErrors) in c:\NLogBuild\src\NLog\Config\XmlLoggingConfiguration.cs:line 247

【问题讨论】:

  • 最好在sharedcache.codeplex.com 的论坛上询问。至于“在 SharedCache 中用 NLog v2.0 替换 NLog v1.1 有多容易”:你试过什么?发布一些代码并告诉我们发生了什么问题。
  • 我尝试使用 NLog v2.0 编译代码并将项目转换为 v2010 Visual Studio。它编译成功。但是,配置文件的格式似乎引发了异常。我对 NLog 不是很熟悉。所以我可能可以在这里发布 NLog 配置文件。
  • 这是一个好主意,并将其更多地放在可回答的类别中:) 您也可以发布您遇到的例外情况吗?
  • @MerlynMorgan-Graham,请查看更新后的帖子。谢谢。

标签: silverlight caching nlog shared-cache


【解决方案1】:

我想通了。只需删除以下布局,它现在支持 NLog v2.0。

${aspnet-request:item=logSession}|

【讨论】:

    猜你喜欢
    • 2013-06-16
    • 2021-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多