RE: Logging from a DLL?

Nicko Cadell <[email protected]> Mon, 26 Jan 2004 20:12:00 -0000
Newsgroups gmane.comp.windows.dotnet.log4net.user
Message-ID <[email protected]>
Alejandro,

I assume that the problem you are having is with how to configure log4net
when the calling app is a dll rather than an exe. The way in which your code
calls into log4net should be the same in both cases.

The simple way to configure log4net is to load the configuration data from
the applications .config file. Only applications have .config files, dlls
don't. Actually that is an over simplification, there can only be one config
file for each AppDomain. When hosted inside an exe or a dll you will be
inside an AppDomain. You can find out what the .config file is for your
AppDomain by evaluating the following property:

AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;

This is the file that log4net will try to load the configuration from unless
told otherwise.

You can configure log4net programmatically using one of the
log4net.Config.DOMConfigurator.Configure or
log4net.BasicConfigurator.Configure methods. If you use
log4net.Config.DOMConfigurator.Configure then you need to know where your
configuration file is.

If you need to use different configuration paths for hosting inside an exe
or a dll things become more complicated. Unless you are able to detect the
hosting situation you will be unable to do this. You may be able to use
System.Reflection.Assembly.GetEntryAssembly() to determine if the entry
assembly is an exe or a dll and change the behaviour accordingly.

Cheers,

Nicko

> -----Original Message-----
> From: Calbazana, Al [mailto:[email protected]] 
> Sent: 23 January 2004 18:51
> To: [email protected]
> Subject: [Log4net-users] Logging from a DLL?
> 
> 
> Hello,
> 
> I have a component that is run from both an .exe and a .dll.  
> This component is set to log and works well when hosted in an 
> .exe (as expected).  The problem I have is that I can not 
> find a good way to log when this component is hosted inside of a .dll.
> 
> Is there any trickery with the app domain that would allow me 
> to use my logger in this context?
> 
> My problemed setup is such that IE needs to create an 
> instance of a .dll which, in turn, hosts the .dll that I wish 
> to log from.  
> 
> Any help is appreciated.
> 
> Thanks,
> 
> Alejandro
> 
> 
> -------------------------------------------------------
> The SF.Net email is sponsored by EclipseCon 2004
> Premiere Conference on Open Tools Development and Integration 
> See the breadth of Eclipse activity. February 3-5 in Anaheim, 
> CA. http://www.eclipsecon.org/osdn 
> _______________________________________________
> Log4net-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/log4net-users
> 


-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn