I created a c# wrapper for log4net.
It has Debug() and Error() methods.
I want to log the method name which logs the record, but If I try to use the %method conv
Scrap that wrapper.
Configuration
To initialize logging you can instead configure it quite easily in your startup project.
3 Add the following:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
Screenshot:
Usage
Now in your classes simply add:
public class YourClass
{
private ILog _logger = LogManager.GetLogger(typeof(YourClass));
// [....]
}
And in your log4net.config
you can now use the logger
property in the output:
Which will print the namespace and type name on every log line (-7
and -40
pads the names so that I get straight columns).
The other great thing is that you can also use a filter on the namespace (to make all database classes log to "databases.log" etc).
You can also use %type{1}
instead if %logger
to get only the class name.