Nlog Callsite layout render captures complete stack trace

58 Views Asked by At

I am on nlog 4.5v and when using Callsite layout render, is there a parameter setting that helps to not capture complete stack trace?

I just need namespace, class and method name of the top most stack.

In version 4.7 onwards, documentation mentions that capturestacktrace=false will work but it doesn’t. It prints nothing with set to false.

Couldn’t find any parameters

1

There are 1 best solutions below

0
Rolf Kristensen On

NLog v4.7.1 extended ${callsite} with option captureStackTrace=false to avoid automatically capturing full StackTrace. But then one is required to explictly provide full StackTrace for the LogEvent to get output.

NLog v5 introduced an optimized fluent LogEvent builder, that uses caller-member-attributes for capturing minimal callsite without using full StackTrace:

_logger.ForInfoEvent()
       .Message("This is a fluent message {0}.", "test")
       .Property("PropertyName", "PropertyValue")
       .Log();