Before we can actually do anything useful with log4net, we need to set it up. This basic configuration, much like NHibernate's own configuration, can be added in multiple places. log4net can be configured in code, as follows:
log4net.Appender.RollingFileAppender fileAppender = new log4net.Appender.RollingFileAppender(); fileAppender.Name = "GeneralLog"; fileAppender.File = "Logs/general.txt"; fileAppender.AppendToFile = true; fileAppender.MaximumFileSize = "100KB"; fileAppender.RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Size; fileAppender.MaxSizeRollBackups = 5; fileAppender.Layout = new log4net.Layout.PatternLayout("%d{HH:mm:ss.fff} [%t] %-5p %c - %m%n"); log4net.Config.BasicConfigurator.Configure(fileAppender);
log4net is more traditionally configured from an app.config
or web.config
file, or as an XML file deployed with the application. This allows much quicker reconfiguration if additional logging is needed. For instance, if you are having an issue in...