log4net: logging NHibernate and my own domain

I was used to use entlib for logging. But as I’m in favour of open source and because I am using NHibernate and Castle ActiveRecord in my applications, decided to use log4net instead. So found a good article about it, and enabled it for my application. But the problem was a very huge log file was producing because of verbose logs from NHibernate.

I’ve been heard that log4net uses hierarchical loggers but did not have a good understanding of it. I was thinking that using hierarchical loggers I can omit NHibernate’s logs and instead show my application’s logs. My bad assumption about hierarchical loggers was that they should be defined in app.config/web.config as nested. Obviously this assumption was wrong. Hierarchical logger in log4net means that you define a root and define all loggers inside it directly. Hierarchy then is understood of “name” attribute of “logger” node. This just acts a C# namespaces. For example you can have “NHibernate” and “NHibernate.SQL”. The second one is a child of the first.

Following guides in this, this, this, this and this link helped me to build my own config that works greatly in my application:

  













type="log4net.Appender.FileAppender">







value="%d [%t] %-5p %c [%x] - %m%n" />
type="log4net.Appender.FileAppender"/>







value="%d [%t] %-5p %c [%x] - %m%n" />












دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *