Please help convert NLog v1.1 to NLog v2.0
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\Prope开发者_JAVA技巧rtyHelper.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 figured it out. Just remove the following layout and it supports for NLog v2.0 now.
${aspnet-request:item=logSession}|
精彩评论