尝试使用环境变量覆盖Nlog配置中的LogLevel,但它不起作用:例如
<logger name="*" writeTo="console">
<filters>
<when condition="level >= '${environment:LOG_LEVEL}' " action="Ignore"/>
</filters>
</logger>
其中LOG_LEVEL设置为LogLevel.Info
与Nlog Env var相同的配置工作:
<variable name="myvar1" value="LogLevel.Info"/>
<logger name="*" writeTo="console">
<filters>
<when condition="level >= '${myvar1}' " action="Ignore"/>
</filters>
</logger>
任何提示如何使用env变量?有些扩展要写吗?
答案 0 :(得分:1)
我知道这有点罗嗦,但也许它有效,直到有人创造了一个正确的解决方案:
<logger name="*" writeTo="console">
<filters>
<when condition="(level >= LogLevel.Fatal and equals('${environment:LOG_LEVEL}','LogLevel.Fatal)" action="Log"/>
<when condition="(level >= LogLevel.Error and equals('${environment:LOG_LEVEL}','LogLevel.Error')" action="Log"/>
<when condition="(level >= LogLevel.Info and equals('${environment:LOG_LEVEL}','LogLevel.Info')" action="Log"/>
<when condition="(level >= LogLevel.Debug and equals('${environment:LOG_LEVEL}','LogLevel.Debug')" action="Log"/>
<when condition="(level >= LogLevel.Trace and equals('${environment:LOG_LEVEL}','LogLevel.Trace')" action="Log"/>
</filters>
</logger>
顺便说一下。好奇为什么你的原始问题不如大于而不是大于。在将LOG_LEVEL配置为警告时会发生,那么它应该记录所有警告或更糟。