It doesn't work down to the method level, but most people add a static ILog per
class based on the class name. You would then set up your configuration to only
log you're class A.
Here is a very untested example of code and config that logs all warnings and
errors, but just debug info from class A;
namespace Blah
{
public class A
{
private static readonly ILog log = LogManager.GetLogger( typeof( A ) );
public void Foo()
{
log.Info( "Log Something" );
}
}
public class B
{
private static readonly ILog log = LogManager.GetLogger( typeof( B ) );
public void Bar()
{
log.Info( "Log Something Else" );
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<layout type="log4net.Layout.PatternLayout">
<ConversionPattern value="%d [%t] %-5p %P %c %m%n" />
</layout>
</appender>
<root>
<level value="WARN" />
<appender-ref ref="FileAppender" />
</root>
<logger name="Blah.A">
<level value="DEBUG" />
</logger>
</log4net>
</configuration>
Hope this helps. If you want to go down to the method level, I would suggest
adding the method name into your logging string and filtering on that. You
could create a logger per method, but that is overkill in my opinion. Anyone
else have a better suggestion for the method level?
Rob Prouse
From: Ross Hinkley [mailto:[EMAIL PROTECTED]
Sent: June-13-08 3:42 PM
To: [email protected]
Subject: filtering on methods
This might seem like I'm a little log4net-challenged (and that may well be),
but after spending some time with the message archives and Google, I could not
figure this one out. So, I turn to you lot for a hand.
Is there a quick and simple way to filter messages based on the method, class,
or namespace?
I'm thinking of a situation where you have class A using class B in a has-a
relationship, where class B is just a helper class. For debugging purposes,
having output from class B is well and good, but it generates a surfeit of
data. Say I still want to debug class A without having log information for
class B. How would I go about doing that?
Thanks in advance,
Ross