当布局渲染输出为空时,防止NLog渲染内部文本 [英] Prevent NLog from rendering inner text when layout render output is empty

查看:84
本文介绍了当布局渲染输出为空时,防止NLog渲染内部文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将NLog错误电子邮件文本的内容放入文件中,并使用FileContents渲染器进行渲染.我想做的是,如果布局渲染器产生一个空字符串,则隐藏html输出的某些部分

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? }

NLog不喜欢这种嵌套的东西:

And NLog doesn't like this nested stuff:

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

推荐答案

NLog不喜欢这种嵌套的东西:

And NLog doesn't like this nested stuff:

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

由于冒号,这是NLog中的错误.从NLog 4.2开始,此操作现在应该起作用,因此解决方案是升级NLog.请参阅此问题在GitHub上

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

这篇关于当布局渲染输出为空时,防止NLog渲染内部文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆