是否有正确的方法来抑制这些Log4Net启动消息?
log4net: Configuration update mode [Merge].
log4net: Logger [root] Level string is [ALL].
log4net: Logger [root] level set to [name="ALL",value=-2147483648].
log4net: Loading Appender [Console] type: [log4net.Appender.ConsoleAppender]
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [ConversionPattern] to String value [%5level - %message%newline]
log4net: Converter [level] Option [] Format [min=5,max=2147483647,leftAlign=False]
log4net: Converter [literal] Option [ - ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [Layout] to object [log4net.Layout.PatternLayout]
log4net: Created Appender [Console]
log4net: Adding appender named [Console] to logger [root].
log4net: Loading Appender [RollingFile] type: [log4net.Appender.RollingFileAppender]
log4net: Setting Property [File] to String value [migrator.log]
log4net: Setting Property [AppendToFile] to Boolean value [True]
log4net: Setting Property [RollingStyle] to RollingMode value [Size]
log4net: Setting Property [MaxSizeRollBackups] to Int32 value [10]
log4net: Setting Property [MaximumFileSize] to String value [10MB]
log4net: Setting Property [StaticLogFileName] to Boolean value [True]
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [ConversionPattern] to String value [%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n]
log4net: Setting Property [ConversionPattern] to String value [%date [%thread] %-5level %logger - %message%newline]
log4net: Converter [date] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [literal] Option [ [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [thread] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [literal] Option [] ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [level] Option [] Format [min=5,max=2147483647,leftAlign=True]
log4net: Converter [literal] Option [ ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [logger] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [literal] Option [ - ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [Layout] to object [log4net.Layout.PatternLayout]
log4net: Searched for existing files in [C:\dev\src\SAS-3.4\code\importers\Migrator\Migrator\bin\Release]
log4net: curSizeRollBackups starts at [0]
log4net: Opening file for writing [C:\dev\src\SAS-3.4\code\importers\Migrator\Migrator\bin\Release\migrator.log] append [True]
log4net: Created Appender [RollingFile]
log4net: Adding appender named [RollingFile] to logger [root].
我们使用了这个技巧:
private static void TemporarilyHideLog4NetOnConsoleMessagesOnStartup()
{
var consoleOut = Console.Out;
var memoryStream = new MemoryStream();
var redirection = new StreamWriter(memoryStream );
Console.SetOut(redirection );
XmlConfigurator.Configure();
Console.SetOut(consoleOut );
}
这似乎有效,但似乎只是想知道是否有官方API。