n日志使用数据库日志中的connectionStringName [英] nlog using the connectionStringName for database logging

查看:603
本文介绍了n日志使用数据库日志中的connectionStringName的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆