logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark.Gib...@ubs.com
Subject RE: Appenders and AppDomains
Date Mon, 17 Jul 2006 11:13:33 GMT
One suggestion if you go down the remoting route.  Always make each
server still logs to a local file.  Cross-appdomain remoting is quite
fast (typically uses named pipes I think), but things can go wrong.  The
most obvious is Thread starvation if you are making use of a lot of
worker threads.  Also, I found marking your remoting interface as
[OneWay] is a good way of alleviating any unwanted hangs whilst logging
is taking place, although this can have a negative affect on the worker
thread pool again.

For a project I worked on, I wrote a logging framework that mimicked the
early dotnet TraceLog stuff (pre log4net) but had much better logging
context (user, thread, stack, etc).  Each physical server had many
appdomains, but one was always set up as the remote logger.  It had a
[OneWay] remoting interface that the rest of the appdomains logged to.
The logger itself then wrote all msgs to the db allowing great
reporting.  This was a fantastic pre-log4net  solution, but it did
occasionally go wrong for spurious db and remoting issues.

Hence - always still log locally to a log file.

-----Original Message-----
From: Nicko Cadell [mailto:nicko@neoworks.com] 
Sent: Sun 16 July 2006 23:25
To: Log4NET User
Subject: RE: Appenders and AppDomains

 

> -----Original Message-----
> From: Morten Andersen [mailto:morten@vianett.no]
> Sent: 15 July 2006 11:07
> To: Log4NET User
> Subject: Re: Appenders and AppDomains
> 
> Thanks Nicko. The remoting solution sounds interesting. Is this a fast

> and reliable solution if you compere it to a RollingFileAppender?

.NET remoting is as reliable as the transport it runs over. If it using
the SMTP protocol [1] then its reliability depends on the mail servers
and how much disk space they have.

Between AppDomains in the same process the remoting calls should be 100%
reliable (assuming that the host machine is responsive and able to
schedule threads).

The intra AppDomain remoting transport is very fast, but remember that
your still have to cost of logging after remoting the event. I have not
done any performance analysis of this scenario so you may want to put
together some tests of your own. The perfromance depends on the remoting
transport selected.

[1]
http://www.ingorammer.com/Software/OpenSourceRemoting/SMTPChannel.html


> When I run BasicConfigurator.Configure() in one or more appdomain the 
> log messages for the domain will be printed in the output window in 
> vs.net. Is this using the MarshalByRef solution?

Which log messages do you mean? Internal ones from log4net or ones from
a log4net appender? What appender are you  using? If you mean the
MarshalByRef solution I outlined in my previous mail, then no as this
has not been implemented.


> Is it best to have one remotingserver for all my hwservers and 
> applications, or should I have one remotingserver for each hwserver?

Again this is a difficult question to answer without knowing your
architecture. If you are going to use remoting to centralise your
logging events you will need to have a way of identifying your logging
server. You will need to select your remoting transport (in memory cross
AppDomain, TCP, other...) and then decide how your are going to identify
the server. TCP transport requires a running server and known port (and
you can only have 1 server instance bound to a single known port). Cross
AppDomain requires a transparent proxy, which you can create using the
Activator.CreateInstance methods (but may not be easy).

So this depends on your architecture, logging requirements, performance
requirements, remoting protocol, and how you can identify your remoting
server. You will need to build a prototype to find the appropriate
solution.

Cheers,
Nicko


> 
> - Morten
> 
> Nicko Cadell wrote: 
> 
> 	AppDomains are logical isolation units akin to lightweight
processes.
> 	log4net cannot exist outside an AppDomain because nothing can
exist
> 	outside an AppDomain. log4net must be configured in each
AppDomain, 
> and
> 	it know nothing about the appenders or configuration in the
other
> 	AppDomains. Each AppDomain will have its own logger hierarchy
and 
> root
> 	logger.
> 	
> 	It is quite a challenge to find all the AppDomains in the
process and
> 	hook them up.
> 	
> 	There are 2 different approaches that I can think of:
> 	
> 	1) Create a MarshalByRef appender implementation, i.e. 
> a class that
> 	extends MarshalByRefObject and implements the IAppender
interface. 
> This
> 	could just be a simple wrapper that forwards the call to another
> 	IAppender, allowing you to reuse the existing appenders. 
> 	This appender and the MarshalByRef appender wrapper would need
to be
> 	created in only 1 AppDomain. You would then need to get a
reference 
> to
> 	this wrapper via remoting into each of the other AppDomains and
then
> 	attach that appender reference to the root logger in that
AppDomain.
> 	
> 	2) The other approach is similar in that it still requires
remoting, 
> but
> 	rather than marshalling the appender across and attaching it to
the
> 	logger hierarchy in all the AppDomains, the events logged in the
> 	AppDomains are sent via remoting to a single published listener
which
> 	re-logs the event it its AppDomain. This allows the logging
events to 
> be
> 	centralised in a single AppDomain, but they can still be logged
in 
> their
> 	own AppDomains.
> 	To do this you will need to use the RemotingAppender in each of
your
> 	AppDomains. The RemotingAppender will sent the LoggingEvent via
.NET
> 	remoting to a published listener. The RemoteLoggingServerPlugin
is a
> 	built-in way of publishing a listener. See the Remoting examples
in 
> the
> 	log4net download, examples\net\1.0\Remoting. In your case rather
than
> 	running separate processes, one of your AppDomains will be the
server
> 	(and receive logging events) and all the other AppDomains will
be the
> 	clients.
> 	
> 	Cheers,
> 	Nicko
> 	
> 	  
> 
> 		-----Original Message-----
> 		From: Morten Andersen [mailto:morten@vianett.no] 
> 		Sent: 14 July 2006 14:30
> 		To: Log4NET User
> 		Subject: Appenders and AppDomains
> 		
> 		Hi
> 		
> 		Is it possible to have one appender for all app domains
in a 
> process?
> 		Each app domain has its own appender, but I also want a 
> 		global appender for all domains.
> 		
> 		- Morten
> 		
> 		
> 		    
> 
> 	
> 	  
> 
> 

Visit our website at http://www.ubs.com

This message contains confidential information and is intended only 
for the individual named.  If you are not the named addressee you 
should not disseminate, distribute or copy this e-mail.  Please 
notify the sender immediately by e-mail if you have received this 
e-mail by mistake and delete this e-mail from your system.

E-mail transmission cannot be guaranteed to be secure or error-free 
as information could be intercepted, corrupted, lost, destroyed, 
arrive late or incomplete, or contain viruses.  The sender therefore 
does not accept liability for any errors or omissions in the contents 
of this message which arise as a result of e-mail transmission.  If 
verification is required please request a hard-copy version.  This 
message is provided for informational purposes and should not be 
construed as a solicitation or offer to buy or sell any securities or 
related financial instruments.


Mime
View raw message