问题描述
这是我的nlog.config文件。我已经打开throwsException。
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>
这将工作和将记录插入数据库中的。不过,我想用的connectionStringName,而不是重新键入ConnectionString中。
当我修改 的ConnectionString 的为 的connectionStringName 的这样的....
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"
到
connectionStringName="ApplicationConnectionString"
我得到一个错误
期待为providerInvariantName'参数非空字符串
I get an error Expecting non-empty string for 'providerInvariantName' parameter
推荐答案
添加 System.Data.SqlClient的
来的属性的ProviderName
在web.config中/ app.config中连接字符串:
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;"/>
这篇关于n日志使用数据库日志中的connectionStringName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!