ILogger.Log has two overloads. You need to create a LoggingEvent and use the 
Log overload that accepts a LoggingEvent. Once you've created a LoggingEvent 
object you can store additional information in Properties:

LoggingEvent loggingEvent = new LoggingEvent(
    declaringType, 
    logger.Repository, 
    logger.Name, 
    Level.Info
    message, 
    ex);

loggingEvent.Properties["GUID"] = Guid.NewGuid();

logger.Log(loggingEvent);

The log4net.Ext.EventID folder contains a more complete example:





http://svn.apache.org/viewvc/logging/log4net/trunk/extensions/net/1.0/

Creating Guids for every message may be too expensive. Do log event ids have to 
be unique across all instances of application or just the current instance? 
Interlocked.Increment can be used as a global counter:

http://msdn2.microsoft.com/en-us/library/dd78zt0c.aspx

If you write to a database you could use the logging table's primary key as a 
unique identifier. Chainsaw can be configured to automatically query a database 
every N seconds.

----- Original Message ----
From: José Joye <[EMAIL PROTECTED]>
To: Log4NET User <[email protected]>
Sent: Saturday, January 20, 2007 4:42:17 AM
Subject: What is the best way to attach  an ID with each logged message?

Hello,

I'm looking for a possibility of attaching an ID to each information logged 
using Log4Net. What will be the best way to use in order to be compatible 
with with existing viewers (chainsaw, ...).

Basically, I want to expose such an overloaded method in my Logger façade:

void Info(int id, string msg);

and I would like to have this information displayed/available in existing 
viewer and appenders.


Thanks,

- José 




Reply via email to