设置Gallio执行日志的日志级别

时间:2013-03-20 00:49:51

标签: c# log4net app-config mbunit gallio

如何配置log4net或我的Gallio测试运行器(Icarus和Echo),以便为Gallio执行日志和我自己的文件追加器使用不同的日志记录级别。我希望我的日志文件具有DEBUG日志级别,而Gallio则具有ERROR日志级别。

我认为这会有效,但Gallio正在阅读两个appender:

  <log4net>
    <appender name="Console" type="log4net.Appender.ConsoleAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%5level [%thread] (%file:%line) - %message%newline" />
      </layout>
    </appender>
    <appender name="File" type="log4net.Appender.FileAppender">
      <file value="test.log" />
      <appendToFile value="false" />
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%5level [%thread] (%file:%line) - %message%newline" />
      </layout>
    </appender>

    <logger name="TestNamespace">
      <level value="DEBUG" />
      <appender-ref ref="File" />
    </logger>
    <root>
      <level value="ERROR" />
      <appender-ref ref="Console" />
    </root>
  </log4net>

1 个答案:

答案 0 :(得分:1)

Gallio正在将控制台输出重定向到其执行日志。所以我需要将ConsoleAppender的阈值设置为Gallio执行日志所需的级别。

  <log4net>
    <appender name="Console" type="log4net.Appender.ConsoleAppender">
      <threshold value="ERROR"/>
      <layout type="log4net.Layout.PatternLayout">
        <!-- Pattern to output the caller's file name and line number -->
        <conversionPattern value="%5level [%thread] (%file:%line) - %message%newline" />
      </layout>
    </appender>
    <appender name="File" type="log4net.Appender.FileAppender">
      <threshold value="DEBUG"/>
      <file value="test.log" />
      <appendToFile value="false" />
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%5level [%thread] (%file:%line) - %message%newline" />
      </layout>
    </appender>

    <root>
      <appender-ref ref="Console" />
      <appender-ref ref="File" />
    </root>
  </log4net>