Exceptions in NLog

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view

Exceptions in NLog


Analyzing memory dump of app we have problems with I noticed
Number of exceptions of this type:       23
Exception MethodTable: 79308b54
Exception object: 017f3f60
Exception type: System.ArgumentNullException
Message: Key cannot be null.
StackTrace (generated):
    SP       IP       Function
    2FF3B33C 7AAB29F7 System.Collections.Specialized.HybridDictionary.get_Item(System.Object)
    2FF3B34C 24F53A3F NLog.LayoutRenderers.EventContextLayoutRenderer.Append(System.Text.StringBuilder, NLog.LogEventInfo)
    2FF3B360 24F52DD3 NLog.Layout.GetFormattedMessage(NLog.LogEventInfo)

But logging seems to be working. Has anyone seen those exceptions? I'm not even sure I should care about them. Maybe that's something internal that just throws and catches/handles it.
Reply | Threaded
Open this post in threaded view

Re: Exceptions in NLog

Jarek Kowalski
Can you post your config ?
NLog Blog
Reply | Threaded
Open this post in threaded view

Re: Exceptions in NLog

This post was updated on .
    <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
  <nlog  throwExceptions="true" internalLogFile="c:\nlog.txt"
         internalLogLevel="Error" autoReload="true"
      <target name="file" xsi:type="File" fileName="C:\Log ${shortdate}.txt"
              layout="${longdate} ${callsite} ${level}: ${message} ${exception:format=Message,StackTrace} ${stacktrace}" />
      <target name="database" type="Database">
          insert into Log
        <parameter name="@msg_time_stamp" layout="${date:format=yyyy-MM-dd HH\:mm\:ss}" />
        <parameter name="@message" layout="${message}" />
        <parameter name="@level" layout="${level}" />
        <parameter name="@msg_attr1" layout="${mdc:item=msg_attr1}"/>
        <parameter name="@msg_attr2" layout="${mdc:item=msg_attr2}"/>
        <parameter name="@msg_attr3" layout="${mdc:item=msg_attr3}"/>
        <parameter name="@msg_time_span" layout="${mdc:item=msg_time_span}"/>
        <parameter name="@costam1" layout="${mdc:item=costam1}"/>
        <parameter name="@costam2" layout="${mdc:item=costam2}"/>
        <parameter name="@stack_trace" layout="${message} ${level:uppercase=true} ${callsite} ${message} \n Exception:${exception:format=type,message,stacktrace:separator=\n} "/> 
        <parameter name="@aspnet_request" layout="${asp-request} ${asp-session} ${callsite} " /> 
        <parameter name="@aspnet_session" layout="${aspnet-session:variable=Szkoda}" />
        <parameter name="@event_context" layout="${event-context}" />
                                <parameter name="@aspnet_user_identity" layout="${aspnet-user-identity}" /> 

      <logger name="*"  minlevel="Off" writeTo="file"/> 
      <logger name="*" minlevel="Trace" writeTo="database"/> 

Ok. I think I know what it is. We don't set all the parameters in MDC every time probably. How bad is this. Sometimes we can't set them because we don't have them. So should I care? Shouldn't NLog check if item in MDC exist instead of reading it and receiving exception (if that's what it happens)
Reply | Threaded
Open this post in threaded view

Re: Exceptions in NLog

Jarek Kowalski
The problem is because of this line:

<parameter name="@event_context" layout="${event-context}" />

You did not indicate which item to use. Should be:

<parameter name="@event_context" layout="${event-context:NAME}" />

Which version of NLog are you using? That should not be allowed in NLog 2.0.

NLog Blog