如何在NLog
中设置配置以将错误及以上错误记录到stderr
并将详细及更高版本记录到stdout
?
// Setting error="true" logs all messages to stderr but I want to log only error messages
// How would I configure to log err messages to stderr and others to stdout?
<target name="console" xsi:type="Console" error="true">
<layout xsi:type="JsonLayout">
<attribute name="Level" layout="${level}" />
<attribute name="Timestamp" layout="${longdate}" />
<attribute name="Message" layout="${message}" />
</layout>
</target>
<logger name="*" minlevel="Trace" writeTo="debug,console" />
var logger = LogManager.GetCurrentClassLogger();
logger.Error("Error Message"); // Writes to stderr
logger.Verbose("Verbose Message"); // Writes to stderr but must write to stdout
非常感谢任何帮助。
答案 0 :(得分:0)
一个解决方案可能是两个目标:
<target name="console" xsi:type="Console">
<layout xsi:type="JsonLayout">
<attribute name="Level" layout="${level}" />
<attribute name="Timestamp" layout="${longdate}" />
<attribute name="Message" layout="${message}" />
</layout>
</target>
<target name="console_error" xsi:type="Console" error="true">
<layout xsi:type="JsonLayout">
<attribute name="Level" layout="${level}" />
<attribute name="Timestamp" layout="${longdate}" />
<attribute name="Message" layout="${message}" />
<attribute name="Exception" layout="${exception}" />
</layout>
</target>
然后有两条规则:
<logger name="*" minlevel="Warn" writeTo="debug,console_error" />
<logger name="*" maxLevel="Info" writeTo="debug,console" />