The Log4Net mailing list is a great source of information about using log4Net, in this forum we collect all the messages in the log4net user list and some selected threads from the developer list.
| Author |
Messages |
|
wijitha
 |
| 12/05/2008 4:46 PM |
|
Hi all
I want to use log4net with my project. here is the simple example i tried.
App.config :
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<log4net> A1 is set to be a ConsoleAppender <appender name="A1" type="log4net.Appender.ConsoleAppender">
A1 uses PatternLayout <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%-4timestamp [%thread] %-5level %logger %ndc - %message%newline" /> </layout> </appender>
Set root logger level to DEBUG and its only appender to A1 <root> <level value="DEBUG" /> <appender-ref ref="A1" /> </root> </log4net> </configuration>
here is the code:
private static readonly ILog log = LogManager.GetLogger(typeof(Program)); static void Main(string[] args) { XmlConfigurator.Configure(); log.Info("Entering application."); log.Debug("Exiting application."); Console.Write("This Log4Net example"); }
This thing is working well. And what i want to do is put the log4net configuration part in a separate file call Log4Net.config
if any one know how to do this please reply me. It is better if u can separately give me the two configuration files. (App.config and Log4Net.config)
thanks a lot wijitha
-- View this message in context: http://www.nabble.com/How-to-use-separate-config-file-for-log4net-tp20856712p20856712.html Sent from the Log4net - Users mailing list archive at Nabble.com.
|
|
|
|
|
Michael Schall
 |
| 12/05/2008 7:14 PM |
|
| You don't need anything in your app.config. Just use the log4net.Config.XmlConfigurator.ConfigureAndWatch method instead as pass it a file with your log4net definitions.
Log4Net.config:
<log4net>
...
<root>
...
</root>
</log4net>
This will also allow you to change logging settings while the program is running.
Mike
|
|
|
|
|
jsinnott@sftcon.com
 |
| 12/05/2008 9:04 PM |
|
|
// initialize the log4net config file
// the system expects to find it in the same folder as the exe file = /bin/debug
FileInfo log4NetConfigFile = new FileInfo("MyCustomConfigFile.config");
if (log4NetConfigFile == null || ! log4NetConfigFile.Exists) throw new Exception("unable to find log4net log file");
XmlConfigurator.Configure(log4NetConfigFile);
|
|
|
|
|
Michael Schall
 |
| 12/06/2008 3:19 PM |
|
No, it is only required once for the process.
Sent from my iPod
|
|
|
|
|
|
| You are not authorized to post a reply. |
|
|
|
ActiveForums 3.7
|