Prevent NLog from rendering inner text when layout render output is empty

血红的双手。 提交于 2019-12-04 11:19:07

I faced a similar problem and got things to work like this:

${when:when=length('${httpContextItems:key=RequestTicket}') > 0:inner=<div>Request ticket ${httpContextItems:key=RequestTicket}</div>}

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...).

And NLog doesn't like this nested stuff:

${when:when=length(${httpContextItems:key=RequestTicket})=0:inner=<div>Request    ticket: ${httpContextItems:key=RequestTicket}</div>}

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!