|
Georg Thanks for the reply. What version of Log4Net are you using? The
release I have (log4net-1.2.0-beta8) does not have the LogicalThreadContext
item. That being said the solution you posted
does look as if it would work, although it does mean that every method that
performs logging will required the “using (..){}” syntax which is
something I would prefer not to do. If possible I am looking for some method
of adding the UID to the logger in the “MyFunc” class constructor
and then not have to worry about it anywhere else. Manuel From:
Georg Jansen [mailto:[EMAIL PROTECTED] Manuel, Will something like this solve it? public cla {
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private string mUid;
public myFunc(string uniqueId)
{
mUid = uniqueId;
}
public void DoSomthing()
{
using (log4net.LogicalThreadContext.Stacks["UID"].Push(mUid))
{
// do somthing ....
log.Debug("Hello");
}
} } Best regards Georg http://www.l4ndash.com - Log4Net Dashboard
/ Log Viewer -----Original Me Hello List, I am currently trying to get my head around using MDC
to handle logging in an environment with multiple simultaneous
requests. Another reason for using MDC is that I need to use the
"%X{MyParameter}" syntax in my conversion pattern. The problem I have is that (by Log4Net design) the MDC
parameters are overwritten by new parameters. As an example, I have
three a "Caller", "Functions" and
"Log4Net". Caller has the following basic code and performs no logging: //--------- Functions f1 = new Functions("uniqueID_1") Functions f2 = new Functions("uniqueID_2") f1.DoRandomThing() f2.DoRandomThing() f1.DoRandomThing() f2.DoRandomThing() //--------- The Functions a a //set the UID from the constructor parameter Logger.MDC.Set("UID", uniqueID); And this code in the DoRandomThing() function //output info log log.Info("hello from dorandomthing"); Using "%X{UID}" in my conversion pattern I
was hoping to get the following log output: uniqueID_1 uniqueID_2 uniqueID_1 uniqueID_2 But I actually get: uniqueID_2 uniqueID_2 uniqueID_2 uniqueID_2 I realise that the reason for this is that the MDC cla am looking for alternative. Therefore if anybody
has any suggestions to a Thanks in advance Manuel p.s. one thing I did consider was using the unique ID
as the logger name : //set logger name this.log =
Logger.LogManager.GetLogger(typeof(Functions) + uniqueID); But this is a tad me amend it. |
- Using MDC to handle multirequests Manuel Reyes
- RE: Using MDC to handle multirequests Georg Jansen
- RE: Using MDC to handle multirequests Manuel Reyes
- RE: Using MDC to handle multirequests Georg Jansen
