How to control Nlog logLevel using environment variables

妖精的绣舞 提交于 2019-12-02 08:25:07

I know this is a little more wordy, but maybe it works, until someone creates a proper fix:

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

Btw. curious why your original question has it as less-than instead of greater-than. Would expect when having configured LOG_LEVEL to Warn, then it should log all warnings or worse.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!