Friday, May 18, 2012
 
The best way to analyze your logs! Minimize
 Log4Net Mail archive   

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.

Subject: log4NET from a class library (dll)
Prev Next
You are not authorized to post a reply.

Author Messages
Ramesh Vijayaraghavan

03/02/2006 4:42 PM  

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

Aaron Morton

03/02/2006 5:01 PM  

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

Nicko Cadell

03/02/2006 6:26 PM  

If you DLL is part of an application that is not using log4net or if you
want the configuration for you assembly to be loaded from a different
config file to that for the rest of the application, you need create a
separate logging Repository for your assembly (DLL).

If you want to configure log4net programmatically you can call one of
the log4net.Config.XmlConfigurator.Configure() methods. Either the one
that takes a FileInfo passing the path to the config file (e.g.
AppDomain.CurrentDomain.SetupInformation.ConfigurationFile) or the
method with no parameters that uses the .NET configuration APIs to load
the configuration from the .config file.

Alternatively add the following assembly level attributes to you DLL.
You can do these in any source file you want, not just the
AssemblyInfo.cs.

[assembly: log4net.Config.Repository("NameOfYourAssemblyHere")]
[assembly: log4net.Config.XmlConfigurator()]

The name of you assembly just needs to be a unique string. This will
load the configuration from the application's .config file.

If you want to load your configuration from a different file you can
use:

[assembly: log4net.Config.XmlConfigurator(ConfigFile="log4net.config")]

The file path is relative to the application base directory.

Cheers,
Nicko

You are not authorized to post a reply.
Forums > Log4Net > Log4Net Mail archive > log4NET from a class library (dll)



ActiveForums 3.7

 

 

 

 

 

 

 

 

Log4Net Dashboard

Log analysis and monitoring made easy!

Log4Net Dashboard is a log viewer that can read log statements from a variety of logging output targets.

You can download a free developer version.

  

Check it out!

On the demonstration site you can try it  with live data.demo.l4ndash.com - Try Log4Net Dashboard with live data

The mail archive is a copy of all the mail sent to the mail address: log4net-user@logging.apache.org, organized as a forum.

If you would like to participate in the mail list, send a mail to log4net-user-subscribe@logging.apache.org.

More information about the mailing list is available on: http://logging.apache.org/log4net/support.html

 

A complete topic list is available and can be viewed here (warning, it takes some time to load)

 

Copyright 2005-2008 by FaktNet AS Terms Of Use Privacy Statement