我正在使用 NLog 记录错误。这是配置代码
<target name="console" xsi:type="AsyncWrapper" >
<target xsi:type="ColoredConsole" layout="${longdate:padding=-10}${callsite:className=false:includeSourcePath=false:methodName=false} | ${message}" >
<highlight-row condition="level >= LogLevel.Info" foregroundColor="Green" backgroundColor="NoChange"/>
</target>
</target>
我在日志事件上设置了一个自定义属性,例如
private LogEventInfo GetLogEvent(string loggerName, LogLevel level, string message, ConsoleColor color)
{
var logEvent = new LogEventInfo(level, loggerName, message);
logEvent.Properties["color"] = color;// color= any console color
}
这设置了“颜色”属性。(在这里说“红色”)
我正在尝试在目标中使用这个“颜色”属性,比如
<highlight-row condition="equals('${color}','Red')" foregroundColor="Red" backgroundColor="NoChange"/>
这个剂量有效,我试过了
<highlight-row condition="equals('${event-context:item=color}','Red')" foregroundColor="Red" backgroundColor="NoChange"/>
但没有运气。
我错过了什么还是有更好的方法来做到这一点?在这种情况下我们可以使用布局渲染器吗?如果是,我们如何实现这一点?