这是我的nlog.config文件。我已经打开了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 时,就像这样....
connectionstring="server=.\SQLExpress;database=Movie;integrated security=true"
到
connectionStringName="ApplicationConnectionString"
我收到错误 期望'providerInvariantName'参数的非空字符串
答案 0 :(得分:13)
在web.config / app.config中的连接字符串中将System.Data.SqlClient
添加到属性ProviderName
:
<add name="ApplicationConnectionString"
providerName="System.Data.SqlClient"
connectionString="server=.\SQLExpress;database=Movie;integrated security=true;"/>