当我运行单元测试时,我使用_.P("My Test Message");
将信息打印到NUnit中的Text Output窗口。
但我的消息被Log4Net消息淹没了。
我想从NUnit文本输出中删除Log4Net消息。
Log4Net配置为仅写入文件。
<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>
在第一次运行单元测试时,我得到以下输出
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 [RollingStyle] 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 []
在随后的单元测试执行中,我得到以下输出。
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 [].
答案 0 :(得分:2)
基于log4net.sourceforge.net的一些快速研究,下面的这个片段启用了NUnit也会调试的调试输出(System.Diagnostics.Debug)。如果删除debug="true"
,则应该获得所需的行为。
<log4net debug="true">