The format of the initialization string does not match the specification starting at index 158 in NLog

I created an nlog configuration with the following code

<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>

and I created three class files in my other layer named D.Exception.Abstract and passed it to my controller.

and when I tried to run the application with the following code

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");  
    }

error: "The format of the initialization string does not comply with the specification starting with index 158".

Please help me ... there aren’t a lot of forums for NLog, and I am starting and applying this for the first time ...

+4
source share
1 answer

Error. The problem was the connection string

Earlier it was

<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" />

and changed it to

<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" />
+3
source

Source: https://habr.com/ru/post/1544310/


All Articles