当前位置: 首页 > 编程语言 > C#

Nlog自定义layoutrenderer分享

时间:2023-04-10 11:55:53 C#

Nlog自定义layoutrenderer谁能给我一个nlog自定义layoutrenderer的样例?例如,我想在im日志中缩进如果我从方法C调用方法B,文本日志文件如下所示:InsideMethodCInsideMethodB等等。这是:[LayoutRenderer("IndentationLayout")]publicsealedclassIndentationLayoutRenderer:LayoutRenderer{//从堆栈计数中减去的值privateuint_ignore=12;//要填充的值。私有字符串_ipadding="|";///设置要忽略的(顶部)堆栈帧数publicuintIgnore{get{return_ignore;}设置{_ignore=值;}}///设置填充值publicstringIndentationPadding{get{return_ipadding;}设置{_ipadding=值;}}protectedoverridevoidAppend(StringBuilderbuilder,LogEventInfoev){//获取当前堆栈深度,插入填充字符。StackTracest=newStackTrace();长缩进=st.FrameCount;缩进=缩进>_ignore?缩进-_ignore:0;for(inti=0;i注册:以上就是C#学习教程:Nlog自定义layoutrenderer分享的全部内容,如果对大家有用还需要进一步了解C#学习教程,希望大家多多关注---if(NLog.Config.ConfigurationItemFactory.Default.LayoutRenderers.AllRegisteredItems.ContainsKey("IndentationLayout"))返回;NLog.Config.ConfigurationItemFactory.Default.LayoutRenderers.RegisterDefinition("IndentationLayout",typeof(IndentationLayoutRenderer));本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处: