Unable to create instance of type Common.Logging.NLog.NLogLoggerFactoryAdapter ...

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Unable to create instance of type Common.Logging.NLog.NLogLoggerFactoryAdapter ...

shapper
Hello,

I am trying to use NLOG with Common Logging in a ASP.NET MVC application.

I installed the latest versions of the following Nuget packages: NLog and Common.Logging.NLog.

I then added to the MVC Application Web.Config the following:

<configuration>

  <configSections>
    <sectionGroup name="common">
      <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
    </sectionGroup>
  </configSections>

  <common>
    <logging>
      <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog">
        <arg key="configType" value="FILE" />
        <arg key="configFile" value="~/NLog.config" />
      </factoryAdapter>
    </logging>   
  </common>

</configuration>

And on the same path as the Web.config file I have the NLog.config file as follows:

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <targets>

    <target xsi:type="Database"
            name="Database"
            dbProvider="System.Data.SqlClient"
            connectionStringName="Context"
            commandText="insert into Logs ([Created],[Host],[Level],[Message],[Source],[Stack],[Type],[User]) values(@Created,@Host,@Level,@Message,@Source,@Stack,@Type,@User)">

      <parameter name="@Created" layout="${date:universalTime=true}" />
      <parameter name="@Host" layout="${machinename}" />
      <parameter name="@Level" layout="${level}" />
      <parameter name="@Message" layout="${message}" />     
      <parameter name="@Source" layout="${callsite:className=true:fileName=false:includeSourcePath=false:methodName=true}" />
      <parameter name="@Stack" layout="${exception:stacktrace}" />
      <parameter name="@Type" layout="${exception:format=type}" />
      <parameter name="@User" layout="${logger}" />
             
    </target> 
  </targets>
 
</nlog>

But when I run my application I keep getting the following error:
Unable to create instance of type Common.Logging.NLog.NLogLoggerFactoryAdapter. Possible explanation is lack of zero arg and single arg NameValueCollection constructors

Any idea what I might be doing wrong?

Thank You,
Miguel
Reply | Threaded
Open this post in threaded view
|

Re: Unable to create instance of type Common.Logging.NLog.NLogLoggerFactoryAdapter ...

lavanya
Miguel,

Today i also faced the same issue and the solution to this i found is:

Set the file properties of the Nlog.config : Copy to OutputDirectory : Copy always.

so that the file will be deployed. And we wont get that erro.

Hope that helps.