Nlog giving exception Possible explanation is lack of zero arg and single arg Common.Logging.Configuration.NameValueCollection constructors

时光毁灭记忆、已成空白 提交于 2019-12-01 20:03:56

When I took a closer look there was an inner exception which complained an nlog 2.0.0 dll was not found. Found a solution as follows

  1. Delete all packages related to nlog and commons logging restart application. If the packages don't get deleted by nuget edit .csproj file and .packages file manually to remove all references to Commons logging or nlog packages.
  2. Then searched for latest nlog package as by entering Common.Logging.Nlog in search text box. Then pick the latest nlog package and it will install all other needed packages for using using nlog through commons logging as a dependency. As shown below:

  3. In your web.config update your factory adapter element In my case i selected 31 so updated it to

    <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog31"> <arg key="configType" value="INLINE" /> </factoryAdapter>

P.S. If you are getting error The configuration section cannot contain a CDATA or text element. Then the problem has to be a type in your config file.

I had this error after moving my Common.Logging and NLog config from one web site to another. I was missing the 'dependentAssembly' blocks from the assembly binding section of the web.config:

<assemblyBinding>
  ...
  <dependentAssembly>
    <assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.2.1.0" newVersion="3.2.1.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Common.Logging.Core" publicKeyToken="af08829b84f0328e" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
  </dependentAssembly>
</assemblyBinding>

Added in case this helps someone else with the same problem as me!

I solved this same error in a different way.

Exception Message returned:

ConfigurationErrorsException: Unrecognized element 'add2'.

Error was with this item:

<add2 key="CommentsButtonEnd" value="]/button"/>

Resolution was: Remove the number 2 as add2 is not a valid config key

<add key="CommentsButtonEnd" value="]/button"/>

Adding in case someone has the same error as me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!