> 
> If I need to log certain custom properties along with the log 
> message what is the best way to do it. I see 
> ThreadContext.Properties and LogicalThreadContext.Properties. 
> Not sure which of the two to use. Would like to know specific 
> scenarios for each of the two. 

The ThreadContext uses thread local storage to hold its values. The
LogicalThreadContext uses the remoting CallContext to hold its values.
If you are using the CallContext then you may want to consider using the
LogicalThreadContext, however the ThreadContext should be sufficient for
most uses.

 
> Also I guess once I set  a property on 
> ThreadContext.Properties it will be logged for all subsequent 
> log calls on that thread. I don't want it that way. I need to 
> attach custom property only for a particular log call and not 
> for subsequent logs calls on the same thread. Is that possible? 

Yes, each LoggingEvent has its own local Properties which override those
from the ThreadContext or GlobalContext. You need to construct the
LoggingEvent yourself which can be done like this:

private static void LogFatalWithCategory(ILog log, string message, int
category)
{
  LoggingEvent loggingEvent = new LoggingEvent(
    typeof(LoggingExample), 
    log.Logger.Repository, 
    log.Logger.Name, 
    Level.Fatal, 
    message, 
    null);
  loggingEvent.Properties["Category"] = category;
  log.Logger.Log(loggingEvent);
}

An alternative is to write an extension to log4net that presents a
different API allowing you to pass in your additional properties. In the
log4net download have a look at the EventID extension at
extensions\net\1.0\log4net.Ext.EventID\cs\src.

Cheers,
Nicko

> 
> Thanks for all the support that this group has been 
> providing. It is really helping me. 
> 
> Cheers,
> Hemant 
> 

Reply via email to