Thanks Ron,
In fact, I do not want to have unicity between messages. The idea is,
whenever we log a message, to give the possibility to also attach an
identifyer (eg: BadParameter, CommunicationProblem) which correspond to
integer number. This will allow us to filter such information.
If a message is log without identifyer, a default one will be used (1 for
debug, 1 for info, ...).
This means that the same ID could be attached to messages issued from
different places in the code.
I will have a look to the eventID.
Thanks,
- José
----- Original Message -----
From: "Ron Grabowski" <[EMAIL PROTECTED]>
To: "Log4NET User" <[email protected]>
Sent: Saturday, January 20, 2007 8:00 PM
Subject: Re: What is the best way to attach an ID with each logged message?
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é