nlog using the connectionStringName for database l

2019-02-09 07:13发布

here is my nlog.config file. I have turned on the throwsException.

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  throwExceptions="true">
      <targets>   
        <target type="Database" name="databaseLog"
        dbProvider="sqlserver"   connectionstring="server=.\SQLExpress;database=Movie;integrated security=true">
            <commandText>
                INSERT INTO [Log] ([Description] , [Level] ) VALUES (@Description,  @Level )
            </commandText>
            <parameter name="@Description" layout="${message}"/> 
            <parameter name="@Level" layout="${level}"/>
        </target>

      </targets>

      <rules>
         <logger name="*" minLevel="Trace"  appendTo="databaseLog"/> 
      </rules>
</nlog>

This will work and will insert records into the database. However I would like to use connectionstringName and not retype the connectionstring. When I change the connectionstring to connectionstringname like this....

connectionstring="server=.\SQLExpress;database=Movie;integrated security=true"

to

connectionStringName="ApplicationConnectionString" 

I get an error Expecting non-empty string for 'providerInvariantName' parameter

1条回答
Summer. ? 凉城
2楼-- · 2019-02-09 07:39

Add System.Data.SqlClient to attribute ProviderName in your connection string in web.config/app.config:

<add name="ApplicationConnectionString" 
providerName="System.Data.SqlClient"
connectionString="server=.\SQLExpress;database=Movie;integrated security=true;"/>
查看更多
登录 后发表回答