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?
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.
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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With