By design Log4net only outputs a message to the console if it can't be configured correctly (http://log4net.sourceforge.net/release/1.2.0.30316/doc/manual/faq.html#reliable).
Logging is a critical part of my application, so want to know if Log4net was configured correctly. I've not been able to find any way to get the info from Log4net, so I wrote this code. But I don't like the strategy at all. Any better suggestions?
TextWriter errorConsole = new StringWriter();
TextWriter defaultErrorConsole = Console.Error;
Console.SetError(errorConsole);
try
{
//configure Log4net
string errorMessage = errorConsole.ToString();
bool initializationError = errorMessage.IndexOf("log4net", StringComparison.OrdinalIgnoreCase) == -1;
if (initializationError)
{
throw ...
}
}
finally
{
Console.SetError(defaultErrorConsole);
}
Also when logging a message, such as calling ILog.Error. Is there a way to see if it was logged?