I am writing a custom NLog target deriving from TargetWithLayout, and I would like to make it optionally write the stack trace, depending on the specific log event. I've defined a nested layout like this (syntax might not be correct):
Layout layout = "${when:${event-properties:StackTraceEnabled}==true:${stacktrace}}";
And I would be creating events like this:
var logEventInfo = new NLog.LogEventInfo(NLog.LogLevel.Error, "Test", "Test")
{
Properties =
{
{ "StackTraceEnabled", true },
}
};
However, this doesn't work, and seems to go against the design of NLog. From the little I've seen, NLog evaluates a GetStackTraceUsage() against its registered targets, and then either always generates the stack trace or never does. Is this correct? Is there a way of customizing stack trace generation at event level?
StackTraceEnabled==false- Julian