logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ron Grabowski <rongrabow...@yahoo.com>
Subject Re: Is there a way to use log4net without the App.Config file all-together?
Date Mon, 23 Apr 2007 21:52:44 GMT
What is Common.Logging? It isn't part of the log4net distribution. 

This is how you configure log4net from a string:

string log4netConfig = getLog4netConfig(); // "<log4net>...</log4net>"
XmlDocument log4netXmlDocument = new XmlDocument();
log4netXmlDocument.LoadXml(log4netConfig);
XmlConfigurator.Configure(
 (XmlElement)log4netXmlDocument.GetElementsByTagName("log4net")[0]);

If you're getting an error when you remove the log4net section from your App.config I suspect
its from the Common.Logging expecting there to be a log4net configuration in the App.config
(hence the setting INLINE). If you don't want the log4net config to be in the file, why not
just put it in its own file?

 <arg key="configType" value="FILE" />

 <arg key="configFile" value="log4net.config" />


----- Original Message ----

From: Theron Kousek <tkousek@keefegroup.com>

To: log4net-user@logging.apache.org

Sent: Monday, April 23, 2007 12:40:58 PM

Subject: Is there a way to use log4net without the App.Config file all-together?



Hi All:

     

   Maybe you can point me in the right direction.   I’m using .NET 1.1 and log4net 1.2.

     

   I was able to get log4net integrated into a WinForms application in C#.   My manager asked
if I could completely remove all log4net dependencies to the App.Config file.

     

   I was able to pull out all of the entries in between:

     

   <log4net>

   ….

   </log4net>

     

   (and now get them from a database row as a clob) and have them streamed into the XmlConfigurator.Configure(…).
  

     

   However, I discovered that I must still have the following in the App.Config:

     

   <?xml version="1.0" encoding="utf-8" ?>   

   <configuration>

     <configSections>        

       <sectionGroup name="common">

         <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"
/>

       </sectionGroup>

       <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"
/>

     </configSections>

     <common>

       <logging>

         <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">

           <!-- choices are INLINE, FILE, FILE-WATCH, EXTERNAL-->

           <!-- otherwise BasicConfigurer.Configure is used   -->

           <!-- log4net configuration file is specified with key configFile-->

           <arg key="configType" value="INLINE" />

         </factoryAdapter>

       </logging>

     </common>  

   </configuration>

     

   If I attempt to “pull out” the above from the app.config and “stream” it into the
XmlConfigurator, the call to 

     

   private static readonly ILog Log = LogManager.GetLogger(typeof(MainForm));          

     

   ends up returning an instance of Common.Logging.Simple.NoOpLogger

   rather than Common.Logging.Log4net.Log4NetLogger.

     

     

   Does anyone know of a way that I can completely do away with the Config file (as per my
manager’s request) and programmatically load the

   Log4net runtime with the data that would otherwise be contained in the App.Config “section
data” section?

     

     

   Thanks in advance for any help!!!

   Theron Kousek 

   Keefe Commissary Network 

   Phone (314) 919-4172 

   Fax: (314) 919-4109 

   Email: tkousek@keefegroup.com 

     

   

  








Mime
View raw message