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: Multiple Loggers Stepping on Toes
Prev Next
You are not authorized to post a reply.

Author Messages
nagooc

06/04/2008 3:54 PM  


I'm working with a 3rd party component that is using Log4net.  Their logger
is configured programatically.

My homegrown components use Log4Net as well and are configured using a
seperate XML file.  As soon as I access a certain line of code in the 3rd
party component, my logger gets its Debug and Info logging disabled.

I'm confused how this is happening.  I'm getting a log by totally different
name.  Anyone ever see this or know how to fix it?
--
View this message in context: http://www.nabble.com/Multiple-Loggers-Stepping-on-Toes-tp17647324p17647324.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

Ron Grabowski

06/04/2008 11:47 PM  

A logger is created from and writes to logger repository (ILoggerRepository). By default there is usually one logging repository per application. Since the 3rd party library has "corrupted" the default repository you can create your own repository and create loggers from there. The repository must have a name. The log4net test cases normally use a guid for their name:

 ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());

You need to tell the XmlConfigurator that you want to configure your specific repository instead of the default repository:

 XmlConfigurator.Configure(rep, new FileInfo("log4net.config"));

When you request a logger you must now pass the name of the repository that you want to create it from:

 ILog log = LogManager.GetLogger(rep.Name, typeof(Program));

You could probably write your own helper method somewhere in your application so that your logger creation code looks like this:

 ILog log = GetLogger(typeof(Program));

Here's a design that a 3rd party library could use to mimic the familiar design of log4net without actually referencing a particular version of log4net and/or without using log4net at all (i.e. someone could write a ConsoleLoggerFactory):

 public static class LogManager
 {
  public static ILog GetLogger( Type type )
  {
   return Adapter.GetLogger( type );
  }

  public static ILog GetLogger( string name )
  {
   return Adapter.GetLogger(name);
  }

  public static ILoggerFactoryAdapter Adapter = new NullLoggerFactory();
 }

 public interface ILoggerFactoryAdapter
 {
  ILog GetLogger(Type type);
  ILog GetLogger(string name);
 }

 public interface ILog
 {
  void Debug(object message);
  void Debug(object message, Exception exception);
  bool IsDebugEnabled { get; }
  // snip
 }

nagooc

06/05/2008 6:06 PM  


Thanks alot.  This is just what I needed.  Works like a champ.

corey

You are not authorized to post a reply.
Forums > Log4Net > Log4Net Mail archive > Multiple Loggers Stepping on Toes



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