Expecting non-empty string for 'providerInvariantName' parameter

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

Expecting non-empty string for 'providerInvariantName' parameter

Darek
Hello.
I'm developing Asp.Net MVC 2 Application, and I have simple NLog configuration file as follow (NLog.config):

<?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" throwExceptions="true">

    <targets>
        <target name="file" xsi:type="File" fileName="${basedir}/log.txt" />

      <target xsi:type="Database"
          name="Database"
          dbProvider="sqlserver"
          useTransactions="false"
          connectionStringName="NLogConnStr"
          keepConnection="false"
          dbDatabase="MvcMusicStore">
        <commandText>
          insert into system_logging(log_date,log_level,log_logger,log_message,log_machine_name, log_user_name, log_call_site, log_thread, log_exception, log_stacktrace) values(@time_stamp, @level, @logger, @message,@machinename, @user_name, @call_site, @threadid, @log_exception, @stacktrace);
        </commandText>
        <parameter name="@time_stamp" layout="${longdate}"/>
        <parameter name="@level" layout="${level}"/>
        <parameter name="@logger" layout="${logger}"/>
        <parameter name="@message" layout="${message}"/>
        <parameter name="@machinename" layout="${machinename}"/>
        <parameter name="@user_name" layout="${windows-identity:domain=true}"/>
        <parameter name="@call_site" layout="${callsite:filename=true}"/>

        <parameter name="@threadid" layout="${threadid}"/>
        <parameter name="@log_exception" layout="${exception}"/>
        <parameter name="@stacktrace" layout="${stacktrace}"/>

      </target> 
    </targets>

    <rules>
        <logger name="*" minlevel="Debug" writeTo="Database" />
    </rules>
</nlog>

But when I'm trying to instantiate my Logger in Global.asax.cs file:

Logger logger = LogManager.GetCurrentClassLogger();

I'm getting exception: Expecting non-empty string for 'providerInvariantName' parameter.

Please give me some info how to fix this.

NLog 2 Beta 1.

Regards
Darek
Reply | Threaded
Open this post in threaded view
|

Re: Expecting non-empty string for 'providerInvariantName' parameter

jfennell
Darek, did you ever find a solution to this problem? I'm having the same thing happen in an ASP.NET (non-MVC) web application when trying to use the connectionStringName property in the NLog config file.

~ Jim Fennell
Reply | Threaded
Open this post in threaded view
|

Re: Expecting non-empty string for 'providerInvariantName' parameter

Jason LaFlair
Administrator
If you are using a connectionstring from your app.config try this:

You should add the System.Data.SqlClient as the value to a new attribute named "ProviderName"

Change
<add name="configNameHere" connectionString="blahblah" />

To
<add name="configNameHere" providerName="System.Data.SqlClient" connectionString="blahblah" />

Found at: http://stackoverflow.com/questions/3599311/entity-framework-expecting-non-empty-string-for-providerinvariantname-parame

Let us know if this helps.

Jason.
Reply | Threaded
Open this post in threaded view
|

Re: Expecting non-empty string for 'providerInvariantName' parameter

jfennell
Thanks Jason,

Adding the providerName to the named connection string did the trick. Wasn't necessary for .NET to work in the web application but it did make the NLog logging work like a charm!

~ Jim F

Ps. My connection strings are stored in an external config file that is referenced in the web.config file, and that still works too!