C# NLog—初始化字符串的格式不符合从索引0开始的规范

C# NLog—初始化字符串的格式不符合从索引0开始的规范,c#,connection-string,nlog,C#,Connection String,Nlog,我已经看到有很多线程引用这个问题。我读过它们,我看不出我写的代码有什么问题 <nlog xmlns="http://www.nlog-project.org/schemas/NLog.mono2.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" internalLogLevel="info" internalLogFile="c:\log.txt"> <t

我已经看到有很多线程引用这个问题。我读过它们,我看不出我写的代码有什么问题

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.mono2.xsd"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        internalLogLevel="info"
        internalLogFile="c:\log.txt">
    <targets>
        <target type="Database"
                name="database"
                connectionstring="NLogPriMIODbConnection">
            <commandText>
                exec dbo.usp_InsertLogEntry @logLevel, @createDate, null,
                                     @message, null, @exception, @stackTrace, @origin
            </commandText>
            <parameter name="@createDate"
                        layout="${longdate}" />
            <parameter name="@origin"
                        layout="${callsite}" />
            <parameter name="@logLevel"
                        layout="${level}" />
            <parameter name="@message"
                        layout="${message}" />
            <parameter name="@exception"
                        layout="${exception:format=Message,StackTrace}" />
            <parameter name="@stackTrace"
                        layout="${stacktrace}" />
        </target>
    </targets>

    <rules>
        <logger name="*"
                minlevel="Trace"
                writeTo="database" />
    </rules>
</nlog>

exec dbo.usp_InsertLogEntry@logLevel,@createDate,null,
@消息,null,@exception,@stackTrace,@origin
连接字符串符合SQL 2012的标准

<connectionStrings>
    <add 
       name="NLogPriMIODbConnection" 
       connectionString="Server=.\SQLExpress;Database=local.XXX;User Id=sa;Password=XXX;" 
       providerName="System.Data.SqlClient" />
  </connectionStrings>

这个我找不到的神秘问题是什么


谢谢

在NLog配置中,您使用了
连接字符串
,它需要实际字符串(即服务器、用户名、密码等)。如果您希望它使用web/app配置中的命名连接字符串,则需要使用
connectionstring

在NLog配置中,您使用了
connectionstring
,它需要实际字符串(即服务器、用户名、密码等)。如果您希望它使用web/app配置中的命名连接字符串,则需要使用
connectionstring

在NLog配置中,您使用了
connectionstring
,它需要实际字符串(即服务器、用户名、密码等)。如果您希望它使用web/app配置中的命名连接字符串,则需要使用
connectionstring

在NLog配置中,您使用了
connectionstring
,它需要实际字符串(即服务器、用户名、密码等)。如果您希望它使用web/app配置中的命名连接字符串,则需要改用
connectionstringname

使用您的值,将连接字符串作为目标的嵌套节点,我的将是这样的。我确信还有其他的方法可以做到这一点,但这就是我当前的配置,它是如何工作的

或者,如果您希望从app.config中提取连接字符串(如其他答案中所述),您可能希望使用ConnectionString属性

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.mono2.xsd"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     internalLogLevel="info" internalLogFile="c:\log.txt">
  <targets>
    <target type="Database" name="database">
      <connectionStrings>
        <add name="NLogPriMIODbConnection" connectionString="Server=.\SQLExpress;Database=local.XXX;User Id=sa;Password=XXX;" providerName="System.Data.SqlClient" />
      </connectionStrings>
      <commandText>
        exec dbo.usp_InsertLogEntry @logLevel, @createDate, null, @message, null, @exception, @stackTrace, @origin
      </commandText>
      <parameter name="@createDate" layout="${longdate}" />
      <parameter name="@origin" layout="${callsite}" />
      <parameter name="@logLevel" layout="${level}" />
      <parameter name="@message" layout="${message}" />
      <parameter name="@exception" layout="${exception:format=Message,StackTrace}" />
      <parameter name="@stackTrace" layout="${stacktrace}" />
    </target>
  </targets>

  <rules>
    <logger name="*" minlevel="Trace"  writeTo="database" />
  </rules>
</nlog>

exec dbo.usp_InsertLogEntry@logLevel、@createDate、null、@message、null、@exception、@stackTrace、@origin

使用您的值,将连接字符串作为目标的嵌套节点,我的将是这样的。我确信还有其他的方法可以做到这一点,但这就是我当前的配置,它是如何工作的

或者,如果您希望从app.config中提取连接字符串(如其他答案中所述),您可能希望使用ConnectionString属性

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.mono2.xsd"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     internalLogLevel="info" internalLogFile="c:\log.txt">
  <targets>
    <target type="Database" name="database">
      <connectionStrings>
        <add name="NLogPriMIODbConnection" connectionString="Server=.\SQLExpress;Database=local.XXX;User Id=sa;Password=XXX;" providerName="System.Data.SqlClient" />
      </connectionStrings>
      <commandText>
        exec dbo.usp_InsertLogEntry @logLevel, @createDate, null, @message, null, @exception, @stackTrace, @origin
      </commandText>
      <parameter name="@createDate" layout="${longdate}" />
      <parameter name="@origin" layout="${callsite}" />
      <parameter name="@logLevel" layout="${level}" />
      <parameter name="@message" layout="${message}" />
      <parameter name="@exception" layout="${exception:format=Message,StackTrace}" />
      <parameter name="@stackTrace" layout="${stacktrace}" />
    </target>
  </targets>

  <rules>
    <logger name="*" minlevel="Trace"  writeTo="database" />
  </rules>
</nlog>

exec dbo.usp_InsertLogEntry@logLevel、@createDate、null、@message、null、@exception、@stackTrace、@origin

使用您的值,将连接字符串作为目标的嵌套节点,我的将是这样的。我确信还有其他的方法可以做到这一点,但这就是我当前的配置,它是如何工作的

或者,如果您希望从app.config中提取连接字符串(如其他答案中所述),您可能希望使用ConnectionString属性

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.mono2.xsd"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     internalLogLevel="info" internalLogFile="c:\log.txt">
  <targets>
    <target type="Database" name="database">
      <connectionStrings>
        <add name="NLogPriMIODbConnection" connectionString="Server=.\SQLExpress;Database=local.XXX;User Id=sa;Password=XXX;" providerName="System.Data.SqlClient" />
      </connectionStrings>
      <commandText>
        exec dbo.usp_InsertLogEntry @logLevel, @createDate, null, @message, null, @exception, @stackTrace, @origin
      </commandText>
      <parameter name="@createDate" layout="${longdate}" />
      <parameter name="@origin" layout="${callsite}" />
      <parameter name="@logLevel" layout="${level}" />
      <parameter name="@message" layout="${message}" />
      <parameter name="@exception" layout="${exception:format=Message,StackTrace}" />
      <parameter name="@stackTrace" layout="${stacktrace}" />
    </target>
  </targets>

  <rules>
    <logger name="*" minlevel="Trace"  writeTo="database" />
  </rules>
</nlog>

exec dbo.usp_InsertLogEntry@logLevel、@createDate、null、@message、null、@exception、@stackTrace、@origin

使用您的值,将连接字符串作为目标的嵌套节点,我的将是这样的。我确信还有其他的方法可以做到这一点,但这就是我当前的配置,它是如何工作的

或者,如果您希望从app.config中提取连接字符串(如其他答案中所述),您可能希望使用ConnectionString属性

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.mono2.xsd"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     internalLogLevel="info" internalLogFile="c:\log.txt">
  <targets>
    <target type="Database" name="database">
      <connectionStrings>
        <add name="NLogPriMIODbConnection" connectionString="Server=.\SQLExpress;Database=local.XXX;User Id=sa;Password=XXX;" providerName="System.Data.SqlClient" />
      </connectionStrings>
      <commandText>
        exec dbo.usp_InsertLogEntry @logLevel, @createDate, null, @message, null, @exception, @stackTrace, @origin
      </commandText>
      <parameter name="@createDate" layout="${longdate}" />
      <parameter name="@origin" layout="${callsite}" />
      <parameter name="@logLevel" layout="${level}" />
      <parameter name="@message" layout="${message}" />
      <parameter name="@exception" layout="${exception:format=Message,StackTrace}" />
      <parameter name="@stackTrace" layout="${stacktrace}" />
    </target>
  </targets>

  <rules>
    <logger name="*" minlevel="Trace"  writeTo="database" />
  </rules>
</nlog>

exec dbo.usp_InsertLogEntry@logLevel、@createDate、null、@message、null、@exception、@stackTrace、@origin

我怎么可能没有注意到这一点!谢天谢地,我可能没有注意到!谢天谢地,我可能没有注意到!谢天谢地,我可能没有注意到!谢谢