I put the contents of my NLog error email text into a file and render it using a a FileContents renderer. What I'd like to do is hide certain parts of html output if a layout renderer produces an empty string
<div>Request ticket: ${httpContextItems:key=RequestTicket}</div>
I am not sure of the syntax of the when condition/property. Here are some attempts:
${httpContextItems:key=RequestTicket:when:length>0}
<div>Request ticket: ${httpContextItems:key=RequestTicket}</div>
${??? How to enclose? }
And NLog doesn't like this nested stuff:
${when:when=length(${httpContextItems:key=RequestTicket})=0:inner=<div>Request ticket: ${httpContextItems:key=RequestTicket}</div>}
I faced a similar problem and got things to work like this:
Note that I had to drop the colon after Request ticket. NLog kept on cutting text before or after the colon, no matter what I tried (escaping with \, used ${literal}, replaced colon with its ASCII code, put the colon in a separate variable...).
This was a bug in NLog due to the colon. This should work now since NLog 4.2, so the solution is, upgrade NLog. See this issue on GitHub