You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Ramesh Vijayaraghavan <sc...@hotmail.com> on 2006/03/02 16:42:22 UTC
log4NET from a class library (dll)
Hello,
I want to log messages from a class library(dll).This dll is called by a
third party application on which I have no control. In other words, I cannot
make the third party application read a app.config file.
A dll by its very nature does not allow loading of app.config file. I am
also not able to find an AssemblyInfo.cs file to make changes to point to
the config file.
I can hard code log4net as follows
FileAppender appender = new log4net.Appender.FileAppender(
new log4net.Layout.PatternLayout("%d [%t]%-5p %c;- %m%n"),logFile);
// using a FileAppender with a PatternLayout
log4net.Config.BasicConfigurator.Configure(appender);
But this means that the log file is hardcoded and cannot be configured. How
can I make the dll read the config file.
Thanks,
scoliodonAThotmailDOTcom
Re: log4NET from a class library (dll)
Posted by Aaron Morton <lo...@the-mortons.org>.
Ramesh,
The overloaded XmlConfigurator.Configure method maybe what you need,
one of the overloads takes a FileInfo.
http://logging.apache.org/log4net/release/sdk/index.html
If your dll is running in the same AppDomain as the exe that is
using it, you may run into problems as the EXE will want log4net
configured its way and you may want it configured another. I *think* in
this situation you will want to create a repository for your dll and
have you configuration apply to that only. There is some info here
http://logging.apache.org/log4net/release/manual/repositories.html
aaron
Ramesh Vijayaraghavan wrote:
>
> Hello,
>
> I want to log messages from a class library(dll).This dll is called by
> a third party application on which I have no control. In other words,
> I cannot make the third party application read a app.config file.
>
> A dll by its very nature does not allow loading of app.config file. I
> am also not able to find an AssemblyInfo.cs file to make changes to
> point to the config file.
>
> I can hard code log4net as follows
>
> FileAppender appender = new log4net.Appender.FileAppender(
> new log4net.Layout.PatternLayout("%d [%t]%-5p %c;-
> %m%n"),logFile);
> // using a FileAppender with a PatternLayout
> log4net.Config.BasicConfigurator.Configure(appender);
>
>
> But this means that the log file is hardcoded and cannot be
> configured. How can I make the dll read the config file.
>
>
> Thanks,
> scoliodonAThotmailDOTcom
>
>
>