asp.net – 初始化字符串的格式不符合从NLog中的索引158开始的规范

我使用以下代码创建了nlog配置

<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true" internalLogFile="c:\nlog.txt" internalLogLevel="Debug">
<targets>
  <target name="Console" xsi:type="Console" layout="${level:uppercase=true} ${message}" />
  <target name="DelivrosLogFile" xsi:type="File" fileName="C:\DelivrosLogs\Delivros.log" layout="${longdate} |${message}| ${stacktrace}" />
  <target xsi:type="Database" name="DelivrosDatabaseLogging" connectionStringName="DelivrosNlog" commandText="INSERT INTO tbl_ErrorLogIn( Event_ID,Priority,Severity,Title,Timestamp,MachineName,AppDomainName,PocessID,ProcessName,ThreadName,Win32ThreadId,Message,FormattedMessage) VALUES (@Event_ID,@Priority,@Severity,@Title,@Timestamp,@MachineName,@AppDomainName,@PocessID,@ProcessName,@ThreadName,@Win32ThreadId,@Message,@FormattedMessage)">
    <parameter name="@Event_ID" layout="0" />
    <parameter name="@Priority" layout="3" />
    <parameter name="@Severity" layout="${level}" />
    <parameter name="@Title" layout="Journal API" />
    <parameter name="@Timestamp" layout="${date}" />
    <parameter name="@MachineName" layout="${machinename}" />
    <parameter name="@AppDomainName" layout="Journal API" />
    <parameter name="@PocessID" layout="${processid}" />
    <parameter name="@ProcessName" layout="${processname}" />
    <parameter name="@ThreadName" layout="${threadname}" />
    <parameter name="@Win32ThreadId" layout="${threadid}" />
    <parameter name="@Message" layout="${exception}" />
    <parameter name="@FormattedMessage" layout="${message} " />
  </target>
</targets>
<rules>
  <logger name="*" levels="Info,Warn,Error,Fatal" writeTo="Console" />
  <logger name="*" levels="Info,Warn,Fatal" writeTo="DelivrosLogFile" />
  <logger name="*" levels="Error" writeTo="DelivrosDatabaseLogging" />
</rules>

我在另一个名为D.Exception.Abstract的图层中创建了三个类文件,并将其引用到我的控制器中.

当我尝试使用以下代码运行应用程序时

public ActionResult UserRegistration()
    {

        //return View("UserRegistration");                
        logger.Info("We're on the Index page for Activities");

        try
        {
            throw new System.Exception("A test exception");
        }
        catch (System.Exception ex)
        {
            logger.Error("An error has occurred", ex);
        }
        return View("UserRegistration");  
    }

错误抛出是“初始化字符串的格式不符合从索引158开始的规范.”

请帮助我… NLog没有太多的论坛…我是初学者,第一次实现这个…

最佳答案 错误已解决.问题出在连接字符串上

以前是这样的

<add name="DNlog" connectionString="data source=192.168.0.12\SQL2012;initial catalog=D;persist security info=True;user id=userid;password=Password;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.SQLClient" />

并改为

<add name="DNlog" connectionString="data source=192.168.0.12\SQL2012;initial catalog=D;persist security info=True;user id=userid;password=Password;" providerName="System.Data.SQLClient" />
点赞