Exceptions in NLog

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

Exceptions in NLog

Peri
Hi.

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.
InnerException:
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
Administrator
Can you post your config ?
NLog Blog
Reply | Threaded
Open this post in threaded view
|

Re: Exceptions in NLog

Peri
This post was updated on .
<configuration>
  <configSections>
    <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
  </configSections>
  <nlog  throwExceptions="true" internalLogFile="c:\nlog.txt"
         internalLogLevel="Error" autoReload="true"
         xmlns="http://www.nlog-project.org/schemas/NLog.xsd" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <targets> 
      <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">
        <dbProvider>mssql</dbProvider>
        <dbHost>host</dbHost>
        <dbDatabase>baza</dbDatabase>
        <dbUserName>username</dbUserName>
        <dbPassword>password</dbPassword>
        <commandText>
          insert into Log
          (parent_id,msg_time_stamp,msg_text,log_level,msg_attr1,msg_attr2,msg_attr3,msg_time_span,eFolderID,SzkodaNr,aspnet_request,aspnet_session,event_context,aspnet_user_identity,stack_trace)
          VALUES  
                 (0,@msg_time_stamp,@message,@level,@msg_attr1,@msg_attr2,@msg_attr3,@msg_time_span,@eFolderId,@SzkodaNr,@aspnet_request,@aspnet_session,@event_context,@aspnet_user_identity,@stack_trace);
        </commandText>
       
        <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}" /> 

      </target>
    </targets>
    <rules>
      <logger name="*"  minlevel="Off" writeTo="file"/> 
      <logger name="*" minlevel="Trace" writeTo="database"/> 
    </rules>
  </nlog> 
</configuration>

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

Jarek
NLog Blog