0

I try to log my request for debugging purposes using Nlog with .net core 2.2. I successfully created a config that logs into the database, but some long messages are getting truncated. here is my Target config :

<target name="database" xsi:type="Database"
   dbProvider="sqlserver"
   dbHost="${configsetting:name=NlogConnection.DbHost}"
   dbDatabase="${configsetting:name=NlogConnection.Database}"
   dbUserName="${configsetting:name=NlogConnection.User}"
   dbPassword="${configsetting:name=NlogConnection.Password}">

  <commandText>
    insert into dbo.Log (
    URL, Logged, Level, Message,
    Logger, Callsite, Exception,isProduction
    ) values (
    @URL, @Logged, @Level, @Message,
    @Logger, @Callsite, @Exception,@isProduction
    );
    delete from Log where Logged &lt;= DATEADD(DAY, -30, GETDATE());

  </commandText>

  <parameter name="@URL" layout="${event-properties:url}" />
  <parameter name="@Logged" layout="${date}" />
  <parameter name="@Level" layout="${level}" />
  <parameter name="@Message" layout="${message}" />
  <parameter name="@Logger" layout="${logger}" />
  <parameter name="@Callsite" layout="${callsite}" />
  <parameter name="@Exception" layout="${exception:tostring}" />
  <parameter name="@isProduction" layout="${event-properties:isProduction}" />
</target>

here is last lines in VS where information sent into the logger :

        body = builder.ToString() + Environment.NewLine + $"Request body:{body}" + " ===    EOF    ==="; // debug mode in VS body holds ALL of the data, I can copy the expression and see in notepad it's all there . 

            logger.LogInformation("isProd: {isProduction} , targeturl {url} , req {req}", coreConstants.Bools.defaults.isProd, new { url = context?.Request?.Host + context?.Request?.Path }, body);

if I debug in VS sending a large request I can see that the string variable holding my body request contains all the information that as been sent. but when Logged I can see that the message is being truncated .

Any Help is much appreciated .

Nadav Caridi
  • 33
  • 1
  • 4

0 Answers0