/log4net

log4net walk through

Primary LanguageC#

log4net testing

log4net walk through

  1. acquire a logger log4net.ILog log = log4net.LogManager.GetLogger(typeof(System.Action)); typeof(System.Action) will be the name of the logger

  2. direct log4net to its config a) add this to start up code XmlConfigurator.ConfigureAndWatch( new FileInfo(logFilePath + "/Configuration/Log4Net.config")); b) or add this to assemblyinfo.cs [assembly:log4net.Config.XmlConfigurator(Watch = true)]

  3. log4net configuration a) need a section named "log4net"

b) need a root in section

c) detailed log4net configuration is in the root

d) appenders are like log sinks. There can be multiple of them. They work independently in parallel. Appenders referenced in need to defined as well e.g. the follow code defines 3 appenders MyAppender sends all log entries to console MyFileAppender sends all log entries to application.log RollingFileAppender sends all log entries to rolling.log file. In addition, it keeps the size of the file under 1MB and the number of files under 5.