Why is this call to the logger throwing Input string was not in a correct format
error?
I am logging the message like this:
_logger.LogDebug("MQTT Profile | Profile Id: {0} | Client Name: {client} | CONNECTED", profile.Id, profile.ClientName);
And this message is appearing in the NLog internal log
2024-08-07 11:26:13.7785 Warn Error when formatting a message. Exception: System.FormatException: Input string was not in a correct format.
at System.Text.StringBuilder.FormatError()
at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
at NLog.MessageTemplates.TemplateRenderer.Render(String template, IFormatProvider formatProvider, Object[] parameters, Boolean forceTemplateRenderer, StringBuilder sb, IList`1& messageTemplateParameters)
at NLog.Internal.LogMessageTemplateFormatter.AppendFormattedMessage(LogEventInfo logEvent, StringBuilder builder)
at NLog.LogEventInfo.AppendFormattedMessage(ILogMessageFormatter messageFormatter, StringBuilder builder)
And this is my Nlog.config
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogLevel="Warn"
internalLogFile="App_Data/logs/internal-nlog.txt">
<extensions>
<add assembly="NLog.Web.AspNetCore" />
<add assembly="OrchardCore.Logging.NLog" />
</extensions>
<targets>
<!-- file target -->
<target xsi:type="File" name="file"
fileName="${var:configDir}/App_Data/logs/orchard-log-${shortdate}.log"
layout="${longdate}|${orchard-tenant-name}|${aspnet-traceidentifier}|${event-properties:item=EventId.Id}|${logger}|${uppercase:${level}}|${message} ${exception:format=ToString,StackTrace}" />
<!-- console target -->
<target xsi:type="Console" name="console" >
<layout xsi:type="JsonLayout">
<attribute name="timestamp" layout="${longdate}" />
<attribute name="level" layout="${level:uppercase=true}" />
<attribute name="message" layout="${message}" />
<attribute name="callSite" layout="${callsite}" />
<attribute name="exception" layout="${exception:format=message}" />
<attribute name="stacktrace" layout="${exception:format=stacktrace}" />
<atrribute name="fullMessage" layout="${longdate}|${orchard-tenant-name}|${aspnet-traceidentifier}|${event-properties:item=EventId.Id}|${logger}|${uppercase:${level}}|${message} ${exception:format=ToString,StackTrace}" />
</layout>
</target>
</targets>
<rules>
<!-- all warnings and above go to the file target -->
<logger name="*" minlevel="Warn" writeTo="file" />
<!-- all info and above go to the console target -->
<logger name="*" minlevel="Debug" writeTo="console" />
<!-- the hosting lifetime events go to the console -->
<!--<logger name="Microsoft.Hosting.Lifetime" minlevel="Info" writeTo="console" />-->
</rules>
</nlog>