请帮助将 NLog v1.1 转换为 NLog v2.0
我想在我们的 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
I would like to use Sharedcache (sharedcache.codeplex.com) in our Silverlight v4.0 project. However, we are using NLog v2.0 for the client logging. SharedCache currently release only support NLog v1.1 which will collide with NLog v2.0 on our web server.
So I decided to convert Sharedcache windows service to use NLog v2.0. The compilation was successful. But as soon as I start the service, I got this error. Can somebody familiar with NLog help? I think it is complaining about the layout.
Here is the windows service configuration file:
<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>
When I started the service in Visual Studio, I got the following NLog exception:
{"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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想通了。只需删除以下布局即可支持 NLog v2.0。
I figured it out. Just remove the following layout and it supports for NLog v2.0 now.