eiu*_*165 8 logging nlog asp.net-mvc-3
这是我的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>
Run Code Online (Sandbox Code Playgroud)
这将工作,并将记录插入数据库.但是我想使用connectionstringName而不是重新键入connectionstring.当我改变的ConnectionString到的connectionStringName这样....
connectionstring="server=.\SQLExpress;database=Movie;integrated security=true"
Run Code Online (Sandbox Code Playgroud)
至
connectionStringName="ApplicationConnectionString"
Run Code Online (Sandbox Code Playgroud)
我得到一个错误期望'providerInvariantName'参数的非空字符串
Nic*_*ick 13
在web.config/app.config中的连接字符串中添加System.Data.SqlClient属性ProviderName:
<add name="ApplicationConnectionString"
providerName="System.Data.SqlClient"
connectionString="server=.\SQLExpress;database=Movie;integrated security=true;"/>
Run Code Online (Sandbox Code Playgroud)