I'm trying to set up a common logging library which determines the ILog
instance based on the current stack and what is the best instance of ILog to use.
I've got my config set up like this:
<log4net>
<!-- appenders ommited -->
<root></root>
<logger name="MyAssembly.MyNamespace">
<level value="WARN" />
<!-- appender list -->
</logger>
</log4net>
And I have a class like this:
namespace MyAssembly.MyNamespace.SubNamespace {
public class MyClass { ... }
}
When I try and get an instance of ILog
I pass in the type (var log = LogManager.GetLogger(typeof(MyClass)).Namespace);
) and I want it to detect that there isn't any logger configured, so it will then go up one level in the namespace tree (to MyAssembly.MyNamespace
) and then see if it is configured at that point.
The problem is that the ILog
returned for MyAssembly.MyNamespace.SubNamespace
is configured for WARN events (and above), essentially what I configured for it's parent. Log4net seems to be returning the ILog
when the required name contains a defined name, rather than when it equals the name.
How do I get Log4net to only return a valid logger when the name is the same as one defined in the config?