Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a difference between log4net.Config.BasicConfigurator.Configure() and log4net.Config.XmlConfigurator.Configure()?

Tags:

.net

log4net

I'm using log4Net for my logging. I also have the following set...

<log4net debug="true"> .. </>

Ok, now, when i have the following code

log4net.Config.BasicConfigurator.Configure();

I don't really get any verbose internal-debug info but I do get displayed anything I log.

Now, when i swap that code out and replace it with this:

log4net.Config.XmlConfigurator.Configure();

I get a lot of internal-debug xml info and anything I log, gets displayed.

So why is this? what's the difference between the two?

like image 547
Pure.Krome Avatar asked Mar 05 '10 23:03

Pure.Krome


People also ask

What is log4net config?

The log4net configuration can be configured using assembly-level attributes rather than specified programmatically. If specified, this is the filename of the configuration file to use with the XmlConfigurator. This file path is relative to the application base directory (AppDomain. CurrentDomain.

How do I use log4net net 6?

Just create a log4net. config file with a log file as an appender, then add two using statements and a single line of code to the new . NET 6 hosting model: //Program.


2 Answers

Yes there is. If you want to configure your logs in code, not from a config, then you'd want to use the BasicConfigurator. @Aaronaught Your post is pretty old, which could explain why your statement:

BasicConfigurator only allows one appender to be configured, at the root, and it can only log to the console.

..is incorrect. I'm using the BasicConfigurator for Event, File and Database logging as of March 2015. It also supports more than one appender per logger. My log4net is configured programmatically, not from a config file.

like image 80
Michael Socha Avatar answered Sep 18 '22 05:09

Michael Socha


BasicConfigurator only allows one appender to be configured, at the root, and it can only log to the console. It doesn't really give you any debug info because there isn't really any debug info.

XmlConfigurator gives you the full set of log4net configuration options - see the Configuration section of the manual for details. It actually starts with an example using BasicConfigurator and proceeds to show you all of the additional properties you can set in the XML.

In a production application you'll probably want to have different loggers with different appenders using different thresholds and areas; you'll probably be receiving log information from several different components and don't want to do exactly the same logging for each one. You'll also definitely want to log to places other than the console - log files, event log, e-mail alerts, that sort of thing. You can only do this with the XmlConfigurator.

like image 23
Aaronaught Avatar answered Sep 20 '22 05:09

Aaronaught