logging-log4net-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicko Cadell" <ni...@neoworks.com>
Subject RE: Renderers
Date Sun, 11 Sep 2005 18:44:51 GMT
 

> I doubt many users need to customize how string messages are 
> rendered. 

It is not a feature that is often requested. But it exists and we
support it.

Adding a custom renderer to the log4net configuration has another
disadvantage in that it leads to a tighter coupling between the
application and the logging library. In general the coupling should be
as loose as possible, it should work with many different configurations.


> Regarding this line:
> 
>  else if (m_repository != null)

The LoggingEvent always checks (m_repository != null) before using it.


> When will a repository be null?

Hopefully never. If a LoggingEvent is serialised and deserialised (e.g.
for remoting) then its repository is not transferred with it, that
remains  behind. Then m_repository will be null. If the LoggingEvent is
re-logged through another repository, by calling the
ILogger.Log(LoggingEvent) method, then the LoggingEvent.EnsureRepository
method is called to set the repository.

Its possible to create other situations where m_repository is null by
calling the public constructors with invalid arguments. Basically the
LoggingEvent is just being cautious.


> The second line in log4net's internal log always seems to be:
> 
>  log4net: DefaultRepositorySelector: defaultRepositoryType 
> [log4net.Repository.Hierarchy.Hierarchy]

The RepositorySelector is used by the LoggerManager to determine which
ILoggerRepository to use. See the LoggerManager.GetRepository methods.
The selector supports looking up a repository by name or by assembly
(the DefaultRepositorySelector does all the magic with assembly
attributes).

The ILoggerRepository obtained from the selector is responsible for
returning the Loggers. The ILogger.Log method is used by the ILog.Debug
etc. methods to generate the log event. It is the Logger.Log method that
is responsible for creating the LoggingEvent object and attaching it to
the logger's ILoggerRepository. Therefore in the normal circumstances
the m_repository will always be set correctly.

Cheers,

Nicko


> 
> --- Nicko Cadell <nicko@neoworks.com> wrote:
> 
> > The renderer is used to convert the m_message object into a string 
> > only if it is not already a string.
> > 
> > We could remove the early test for string, this could then 
> be done by 
> > the default renderer allowing it to be customised by the user.
> > However
> > the performance gain of doing the early test benefits about 
> 99.999% of 
> > users.
> > 
> > If you want to use a renderer then you need to pass in a 
> custom object 
> > to the ILog.Debug() methods rather than a string.
> > 
> > Nicko
> > 
> > > -----Original Message-----
> > > From: Ron Grabowski [mailto:rongrabowski@yahoo.com]
> > > Sent: 11 September 2005 08:11
> > > To: log4net-dev@logging.apache.org
> > > Subject: Renderers
> > > 
> > > LoggingEvent.cs contains this code:
> > > 
> > > public string RenderedMessage
> > > {
> > >  get
> > >  {
> > >   if (m_data.Message == null)
> > >   {
> > >    if (m_message == null)
> > >    {
> > >     m_data.Message = "";
> > >    }
> > >    else if (m_message is string)
> > >    {
> > >     m_data.Message = (m_message as string);
> > >    }
> > >    else if (m_repository != null)
> > >    }
> > >    m_data.Message =
> > m_repository.RendererMap.FindAndRender(m_message);
> > >    }
> > >    else
> > >    {
> > >     // Very last resort
> > >     m_data.Message = m_message.ToString();
> > >    }
> > >   }
> > >   return m_data.Message;
> > >  }
> > > }
> > > 
> > > How is it possible to create a custom StringRender:
> > > 
> > > http://logging.apache.org/log4net/release/manual/configuration
> > > .html#renderers
> > > 
> > > if this code:
> > > 
> > >  else if (m_message is string)
> > > 
> > > is called before checking in the RendererMap?
> > > 
> > > 
> > 
> 
> 
> 

Mime
View raw message