logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erich Eichinger" <E.Eichin...@diamonddogs.cc>
Subject RE: Is there a way to use log4net without the App.Config file all-together?
Date Wed, 25 Apr 2007 08:52:55 GMT
Hi,
 
Common.Logging is an abstraction layer that emerged from the iBatis project across Spring.NET
into it's very own project at sourceforge and aims to decouple applications from concrete
logging implementations such as log4net. You can find the online documentation and sources
at http://netcommon.sourceforge.net/.
 
To remove explicit log4net compile-time dependencies in your project but still use log4net
for logging you need to do the following:
 
1) replace all log4net assembly references with Common.Logging references
2) replace "using log4net;" statements with "using Common.Logging;" 
3) configure Common.Logging to use log4net as a concrete implementation.

I suggest you extract your log4net configuration into an external file "log4net.config" and
configure Common.Logging by

<common>
  <logging>
    <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
      <arg key="configType" value="FILE-WATCH" />
      <arg key="configFile" value="~/log4net.config" />
    </factoryAdapter>
  </logging>
</common>

This causes Common.Logging to configure log4net v1.2.10 using the specified configuration
file and use log4net as concrete logging implementation.

Beware that due to the changed public key from log4net version 1.2.9->1.2.10 there are
also 2 versions  Common.Logging.Log4Net.dll and Common.Logging.Log4Net129.dll


hope this helps,
Erich

________________________________

	From: Rao Rapolu [mailto:rao.rapolu@fintrax.com] 
	Sent: Wednesday, April 25, 2007 10:33 AM
	To: Log4NET User
	Subject: RE: Is there a way to use log4net without the App.Config file all-together?
	
	

	Can you not encrypt the portion of log4net in App.config?

	 

	________________________________

		From: Theron Kousek [mailto:tkousek@keefegroup.com] 
	Sent: 23 April 2007 17:41
	To: log4net-user@logging.apache.org
	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