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 Nicko Cadell <ni...@neoworks.com> on 2005/04/02 21:53:49 UTC

RE: Missing LoggingEvents in RemotingAppender

Sam,

There were some changes to the RemotingAppender to resolve an issue with
call context data. There should be no problem with using the NDC in
conjunction with the RemotingAppender.

If there is an issue we would like to reproduce it so that it can be
fixed.

Do you have a simple reproduction case you can send me? If not how about
the config file and details of the loggers and NDC data set, also the
output you were seeing and the output you expected.

Many thanks,
Nicko

> -----Original Message-----
> From: Sam Smoot [mailto:ssmoot@gmail.com] 
> Sent: 30 March 2005 17:07
> To: log4net-user@logging.apache.org
> Subject: Re: Missing LoggingEvents in RemotingAppender
> 
> Nevermind, I figured it out!
> 
> In the sub-loggers I was using NDC all over the place, but 
> not in the root logger (ClassC). On a 
> wild-stab-in-the-dark-I've-been-working-on-this-for-8-hours-an
> d-am-out-of-ideas-hunch
> I removed all the NDC's and it started working again.
> 
> I could have very well been using NDC's incorrectly in Beta8, 
> but it did work, so I'd consider this a breaking change. 
> Maybe it should go under consideration to have the release 
> notes for Beta9 updated to reflect that so no one else wastes 
> hours with the same problem. :-)
> 
> Thanks, -Sam
> 

Re: Missing LoggingEvents in RemotingAppender

Posted by Sam Smoot <ss...@gmail.com>.
Thanks for the reply and the great library! I was able to duplicate
the problem easily enough. I added this test to the
RemotingAppenderTest:

[Test] public void TestNestedNDC() {
			// Setup the remoting appender
			ConfigureRootAppender(FixFlags.Partial);

			RemoteLoggingSinkImpl.Instance.Events = null;

			testService t = new testService();
			t.test();

			// Wait for the remoted object to be delivered
			System.Threading.Thread.Sleep(1000);

			LoggingEvent[] events = RemoteLoggingSinkImpl.Instance.Events;
			Assertion.AssertEquals("Expect to receive 1 remoted event", 1,
events.Length);
		}

Ignore the Assertion, that's just copy & paste I didn't put the effort
in to make the test pretty :-). You'll want to modify the
RemoteLoggingSinkImpl to add a Trace like so:

public void LogEvents(LoggingEvent[] events)
			{
				Events = events;
				foreach(LoggingEvent e in events) {
					Trace.WriteLine(String.Format("Logger: {0}, Message: {1}",
e.LoggerName, e.RenderedMessage));
				}
			}

It's the Trace's you'll be watching out for. Here's the dummy classes
I made for the test:

namespace company.project {
	public class feature {
		static ILog log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

		public void test() {
			using(NDC.Push("test")) {
				log.Info("feature");
				dal d = new dal();
				d.test();
				log.Info("return");
			}
		}
	}
}

namespace company.project.data {
	public class dal {
		static ILog log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

		public void test() {
			using(NDC.Push("test")) {
				log.Info("return");
			}
		}
	}
}

namespace company.project.userInterfaces {
	public class testService {
		static ILog log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

		public void test() {
			log.Info("begin test.");
			feature f = new feature();
			f.test();
			log.Info("end test.");
		}
	}
}

What you won't see is the log.Info("end test.") above in the Traces.
You would in Beta8, but they're lost in Beta9. Atleast for the
RemotingAppender. They appeared just fine in the
RollingLogFileAppender. Now I'm not sure if the "dal" class is even
necessary. I suspect it isn't and the problem is any NDC used in a
class instantiated by another class in a parallel namespace/loggerName
that doesn't use NDC. Or something like that. I was just duplicating
the structure of our production project we ran into this problem with
with the above code.

So hopefully this will let you reproduce the problem in a few seconds.
Worked for me anyways. Thanks again for your hard work!

On Apr 2, 2005 1:53 PM, Nicko Cadell <ni...@neoworks.com> wrote:
> Sam,
> 
> There were some changes to the RemotingAppender to resolve an issue with
> call context data. There should be no problem with using the NDC in
> conjunction with the RemotingAppender.
> 
> If there is an issue we would like to reproduce it so that it can be
> fixed.
> 
> Do you have a simple reproduction case you can send me? If not how about
> the config file and details of the loggers and NDC data set, also the
> output you were seeing and the output you expected.
> 
> Many thanks,
> Nicko
> 
> > -----Original Message-----
> > From: Sam Smoot [mailto:ssmoot@gmail.com]
> > Sent: 30 March 2005 17:07
> > To: log4net-user@logging.apache.org
> > Subject: Re: Missing LoggingEvents in RemotingAppender
> >
> > Nevermind, I figured it out!
> >
> > In the sub-loggers I was using NDC all over the place, but
> > not in the root logger (ClassC). On a
> > wild-stab-in-the-dark-I've-been-working-on-this-for-8-hours-an
> > d-am-out-of-ideas-hunch
> > I removed all the NDC's and it started working again.
> >
> > I could have very well been using NDC's incorrectly in Beta8,
> > but it did work, so I'd consider this a breaking change.
> > Maybe it should go under consideration to have the release
> > notes for Beta9 updated to reflect that so no one else wastes
> > hours with the same problem. :-)
> >
> > Thanks, -Sam
> >
>