开发者

Prevent Log4Net from writing to NUnit Text Output window

开发者 https://www.devze.com 2023-02-03 10:52 出处:网络
When I run unit tests, I use _.P(\"My Test Message\"); to print information to the Text Output window in NUnit.

When I run unit tests, I use _.P("My Test Message"); to print information to the Text Output window in NUnit.

But my messages are being overwhelmed by Log4Net messages.

I would like to remove the Log4Net messages from my NUnit text output.

Log4Net is configured to write to a file only.

<log4net debug="true">
  <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
    <file value="Log.txt" />
    <appendToFile value="true" />
    <rollingStyle value="Size" />
    <maxSizeRollBackups value="10" />
    <maximumFileSize value="10MB" />
    <staticLogFileName value="true" />
    <param name="DatePattern" value="yyyyMMdd" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%-5p %d - %m%newline" />
    </layout>
  </appender>

  <root>
    <level value="All" />
    <appender-ref ref="RollingLogFileAppender" />
  </root>
</log4net>

On 1st running a Unit Test, I get the following outputs

log4net: XmlHierarchyConfigurator: Configuration update mode [Merge].
log4net: XmlHierarchyConfigurator: Configuration update mode [Merge].
log4net: XmlHierarchyConfigurator: Logger [root] Level string is [All].
log4net: XmlHierarchyConfigurator: Logger [root] Level string is [All].
log4net: XmlHierarchyConfigurator: Logger [root] level set to [name="ALL",value=-2147483648].
log4net: XmlHierarchyConfigurator: Logger [root] level set to [name="ALL",value=-2147483648].
log4net: XmlHierarchyConfigurator: Loading Appender [RollingLogFileAppender] type: [log4net.Appender.RollingFileAppender]
log4net: XmlHierarchyConfigurator: Loading Appender [RollingLogFileAppender] type: [log4net.Appender.RollingFileAppender]
log4net: XmlHierarchyConfigurator: Setting Property [File] to String value [Log.txt]
log4net: XmlHierarchyConfigurator: Setting Property [File] to String value [Log.txt]
log4net: XmlHierarchyConfigurator: Setting Property [AppendToFile] to Boolean value [True]
log4net: XmlHierarchyConfigurator: Setting Property [AppendToFile] to Boolean value [True]
log4net: XmlHierarchyConfigurator: Setting Property [开发者_如何学GoRollingStyle] to RollingMode value [Size]
log4net: XmlHierarchyConfigurator: Setting Property [RollingStyle] to RollingMode value [Size]
log4net: XmlHierarchyConfigurator: Setting Property [MaxSizeRollBackups] to Int32 value [10]
log4net: XmlHierarchyConfigurator: Setting Property [MaxSizeRollBackups] to Int32 value [10]
log4net: XmlHierarchyConfigurator: Setting Property [MaximumFileSize] to String value [10MB]
log4net: XmlHierarchyConfigurator: Setting Property [MaximumFileSize] to String value [10MB]
log4net: XmlHierarchyConfigurator: Setting Property [StaticLogFileName] to Boolean value [True]
log4net: XmlHierarchyConfigurator: Setting Property [StaticLogFileName] to Boolean value [True]
log4net: XmlHierarchyConfigurator: Setting Property [DatePattern] to String value [yyyyMMdd]
log4net: XmlHierarchyConfigurator: Setting Property [DatePattern] to String value [yyyyMMdd]
log4net: PatternParser: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: XmlHierarchyConfigurator: Setting Property [ConversionPattern] to String value [%-5p %d - %m%newline]
log4net: XmlHierarchyConfigurator: Setting Property [ConversionPattern] to String value [%-5p %d - %m%newline]
log4net: PatternParser: Converter [p] Option [] Format [min=5,max=2147483647,leftAlign=True]
log4net: PatternParser: Converter [p] Option [] Format [min=5,max=2147483647,leftAlign=True]
log4net: PatternParser: Converter [literal] Option [ ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [literal] Option [ ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [d] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [d] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [literal] Option [ - ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [literal] Option [ - ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [m] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [m] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: PatternParser: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: XmlHierarchyConfigurator: Setting Property [Layout] to object [log4net.Layout.PatternLayout]
log4net: XmlHierarchyConfigurator: Setting Property [Layout] to object [log4net.Layout.PatternLayout]
log4net: RollingFileAppender: Searched for existing files in [D:\Development\Source\V3.0\SiteMajik.Generators\SiteMajik.Generators.UnitTest]
log4net: RollingFileAppender: Searched for existing files in [D:\Development\Source\V3.0\SiteMajik.Generators\SiteMajik.Generators.UnitTest]
log4net: RollingFileAppender: curSizeRollBackups starts at [0]
log4net: RollingFileAppender: curSizeRollBackups starts at [0]
log4net: FileAppender: Opening file for writing [D:\Development\Source\V3.0\SiteMajik.Generators\SiteMajik.Generators.UnitTest\Log.txt] append [True]
log4net: FileAppender: Opening file for writing [D:\Development\Source\V3.0\SiteMajik.Generators\SiteMajik.Generators.UnitTest\Log.txt] append [True]
log4net: XmlHierarchyConfigurator: Created Appender [RollingLogFileAppender]
log4net: XmlHierarchyConfigurator: Created Appender [RollingLogFileAppender]
log4net: XmlHierarchyConfigurator: Adding appender named [RollingLogFileAppender] to logger [root].
log4net: XmlHierarchyConfigurator: Adding appender named [RollingLogFileAppender] to logger [root].
log4net: XmlHierarchyConfigurator: Hierarchy Threshold []
log4net: XmlHierarchyConfigurator: Hierarchy Threshold []

On subsequent Unit Test executions I get the following output.

log4net:ERROR [TextWriterAppender] Attempted to append to closed appender named [].
log4net:ERROR [TextWriterAppender] Attempted to append to closed appender named [].
log4net:ERROR [TextWriterAppender] Attempted to append to closed appender named [].
log4net:ERROR [TextWriterAppender] Attempted to append to closed appender named [].
log4net:ERROR [TextWriterAppender] Attempted to append to closed appender named [].
log4net:ERROR [TextWriterAppender] Attempted to append to closed appender named [].
log4net:ERROR [TextWriterAppender] Attempted to append to closed appender named [].
log4net:ERROR [TextWriterAppender] Attempted to append to closed appender named [].
log4net:ERROR [TextWriterAppender] Attempted to append to closed appender named [].
log4net:ERROR [TextWriterAppender] Attempted to append to closed appender named [].
log4net:ERROR [TextWriterAppender] Attempted to append to closed appender named [].
log4net:ERROR [TextWriterAppender] Attempted to append to closed appender named [].


Based on some quick research at log4net.sourceforge.net, this snippet below enables the debug output (System.Diagnostics.Debug) which NUnit will also pick up. If you remove the debug="true", you should get the behavior you want.

<log4net debug="true">
0

精彩评论

暂无评论...
验证码 换一张
取 消