2012-01-11 116 views
8

這裏是我的nlog.config文件。我打開了throwsException。nlog使用connectionStringName進行數據庫日誌記錄

<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的connectionStringName這樣....

connectionstring="server=.\SQLExpress;database=Movie;integrated security=true" 

connectionStringName="ApplicationConnectionString" 

我得到期待的「providerInvariantName非空字符串錯誤 '參數

回答

11

A DD System.Data.SqlClient的屬性ProviderName在連接字符串中在web.config中/的app.config:

<add name="ApplicationConnectionString" 
providerName="System.Data.SqlClient" 
connectionString="server=.\SQLExpress;database=Movie;integrated security=true;"/> 
+0

感謝尼克!偉大的作品 – eiu165 2012-01-11 17:37:26

+2

你能否澄清一下,這是去nLog配置或web.config?謝謝。 – AlexVPerl 2016-01-30 17:53:28