asp.net-mvc-3 – 使用connectionStringName进行数据库日志记录的nlog

前端之家收集整理的这篇文章主要介绍了asp.net-mvc-3 – 使用connectionStringName进行数据库日志记录的nlog前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的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’参数的非空字符串

解决方法

将System.Data.sqlClient添加到web.config / app.config中连接字符串中的ProviderName属性
<add name="ApplicationConnectionString" 
providerName="System.Data.sqlClient"
connectionString="server=.\sqlExpress;database=Movie;integrated security=true;"/>
原文链接:https://www.f2er.com/aspnet/251710.html

猜你在找的asp.Net相关文章