Reputation: 690
Is it possible with Nlog in JsonLayout a JsonAttribute as Interger spend. The properties are always output as a string. I have tried the following code example:
So far the edition is correct, just as a string and not a Ineger.
Can help me someone to understand what is wrong?
LayoutRenderer.Register("level", info => info.Level.Ordinal * 100);
var fieldsLayout = new JsonLayout
{
RenderEmptyObject = false,
SuppressSpaces = true
};
fieldsLayout.Attributes.Add(new JsonAttribute("channel", "${channel}"));
fieldsLayout.Attributes.Add(new JsonAttribute("level", "${level}"));
Upvotes: 0
Views: 135
Reputation: 19867
Think it is a bad idea to override the default ${level}
renderer.
The easy solution for level is just doing this:
fieldsLayout.Attributes.Add(new JsonAttribute("level", "${level:format=ordinal}") { Encode = false });
But if you need to have it multiplied by 100 then you need to register a custom layout renderer:
LayoutRenderer.Register("level100", info => info.Level.Ordinal * 100);
fieldsLayout.Attributes.Add(new JsonAttribute("level", "${level100}") { Encode = false });
Upvotes: 2