Nlog: event-properties:item always empty

Created on 18 Mar 2019  路  6Comments  路  Source: NLog/NLog

Hello, first of all thanks for a great framework.
I'm using NLog v4.5.11 with Asp.net Mvc and trying to save a log into db table, here is my NLog config:

```xml
type="Database"
connectionStringName="Test">

INSERT INTO ExceptionLog
(Message, StackTrace, InnerException, ExtraInfo, Date ) VALUES
(@Message, @StackTrace, @InnerException, @ExtraInfo, @Date);

  <parameter name="@Message" layout="${exception:format=message}" />
  <parameter name="@StackTrace" layout="${exception:format=stacktrace}" />
  <parameter name="@InnerException" layout="${exception:format=type,message,method:maxInnerExceptionLevel=5:innerFormat=shortType,message,method}" />
  <parameter name="@ExtraInfo" layout="${event-properties:item=extraInfo}" />
  <parameter name="@Date" layout="${date}" />

  <dbProvider>System.Data.SqlClient</dbProvider>
</target>

<logger name="Test.Namespace.DatabaseLogger" minlevel="Debug" writeTo="database" final="true" />
This is how I call it inside my DatabaseLogger:

public void Error(string message, Exception exception)
{
Logger.Error(exception, "{extraInfo}", "This is some test extra info");
}
```

However, this just inserts an empty string into ExtraInfo column (because property was not found). All other columns are set right. Am I doing something wrong? Any ideas how to fix this?

question

All 6 comments

Could you make a simple Test App where the following NLog-config also fails:

<nlog>
<targets>
<target type="console" name="db" layout="${event-properties:item=extraInfo} - ${message}" />
</targets>
<rules>
<logger name="Test.Namespace.DatabaseLogger" minlevel="Debug" writeTo="db" final="true" />
</rules>
</nlog>

And then attach the solution to this issue?

Maybe it's also a good idea to double check if the value is also empty when writing to the filetarget

First of all thanks for reply's guys. @304NotModified I'll be able to do some checks tomorrow morning, what i managed to do so far is follow @snakefoot suggestion and created Test App, however I cant reproduce bug that I'm experiencing with real app... Sample app works without issue... I must be missing something... I'll also introduce some internalLog's to see if that helps...

@Exerlol Minor detail unrelated to event-properties. You might want to include:

<parameter name="@Type" layout="${exception:format=type}" />

@snakefoot yeah, what I've posted is just a "simplified sample", we are logging much more in real app... Anyways, I feel so dumb, we have quite a few projects inside solution and after some hair pulling I've noticed that class library is referencing latest version of NLog, but web project was using old one, once updated everything started working like a charm... Sorry for all the fuzz, you can close this question, note for others that come across same issue - check your NLog version since event-properties (at least syntax i was using) are NLog 4.5+ feature...hope it helps someone. Thanks to both of you guys!

I'm glad is has been resolved 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

smeegoan picture smeegoan  路  3Comments

Sam13 picture Sam13  路  3Comments

carkov1990 picture carkov1990  路  3Comments

Rapiiidooo picture Rapiiidooo  路  3Comments

Jerefeny picture Jerefeny  路  3Comments